`
yu06206
  • 浏览: 110188 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

Andriod学习笔记系列(3)——常见控件(二)

阅读更多

DataPicker(日期对话框)

Andriod内置的对话框,我们不需要填写时间,只需要上下调动时间

使用步骤:

1.声明监听器,使用内部类

2.复写 onCreateDialog(int id)方法

3.在你需要显示的时候调用showDialog(DATE_PICKER_ID)方法

 

//监听器,用户监听用户点下DatePikerDialog的set按钮时,所设置的年月日
	DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

		@Override
		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			System.out.println(year + "-" + monthOfYear + "-" + dayOfMonth);
		}
	};
protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DATE_PICKER_ID:
			return new DatePickerDialog(this, onDateSetListener, 2010, 11, 25);
		}
		return null;
	}
 

 

SeekBar控件

 

 

可拖动的进度条,像一些常见的软件都会用到,比如音乐播放器,可以快进快退等功能

使用SeekBar的步骤:

1.在布局文件中声明SeekBar

 

<SeekBar
 android:id="@+id/seekbar"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 >

 2.定义一个OnSeekBarChangeListener监听器

 

@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			// TODO Auto-generated method stub
			
		}

 

3.使用SeekBar进度条


ExpandAblelistActivity控件

 

 

使用Expandablelistactivity控件步骤:

1.在布局文件中声明ExpandAblelistActivity控件 

 

<ExpandableListView android:id="@id/android:list"
               android:layout_width="fill_parent" 
               android:layout_height="fill_parent"
               android:drawSelectorOnTop="false"/>
 
     <TextView android:id="@id/android:empty"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:text="No data"/>
 

2.在布局文件中声明Group格式

 

<TextView android:id="@+id/groupTo" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="60px" 
		android:paddingTop="10px"
		android:paddingBottom="10px" 
		android:textSize="26sp" 
		android:text="No data" />
 

3.在布局文件中声明子项的样式

 

<TextView android:id="@+id/childTo" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="50px" 
		android:paddingTop="5px"
		android:paddingBottom="5px" 
		android:textSize="20sp" 
		android:text="No data" />
 

4.创建一个Activity,继承ExpandAblelistActivity

 

/*
 * 创建一个Activity,继承ExpandableListAcitivty
 */
public class MainActivity extends ExpandableListActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}
}
 

5,为Group创建数据

 

//定义一个List,该List对象为一级条目提供数据
		List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
		Map<String, String> group1 = new HashMap<String, String>();
		group1.put("group", "group1");
		Map<String, String> group2 = new HashMap<String, String>();
		group2.put("group", "group2");
		groups.add(group1);
		groups.add(group2)
 

 

6.为子项创建数据

 

//定义一个List,该List对象为第一个一级条目提供二级条目的数据
		List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
		Map<String, String> child1Data1 = new HashMap<String, String>();
		child1Data1.put("child", "child1Data1");
		child1.add(child1Data1);
		Map<String,String> child1Data2 = new HashMap<String,String>();
		child1Data2.put("child", "child1Data2");
		child1.add(child1Data2);
 

 

 

 

  • 大小: 17.1 KB
  • 大小: 16.4 KB
  • 大小: 8.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics