Android 常用系统控件
1. 日期选择器 DatePickerDialog
2. 时间选择器 TimePickerDialog
3. 单选按钮 RadioButton
4. 多选按钮 CheckBox
5. 下拉列表 Spinner
-----------------------------------------------------
显示样式,跟主题有关
-----------------------------------------------------
1. 日期选择器
new DatePickerDialog(ChooseDateActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String theDate = String.format("%d-%d-%d", year, monthOfYear, dayOfMonth); btnChooseDate.setText(theDate); } }, 2015, 8, 18).show();
2. 时间选择器
new TimePickerDialog(ChooseTimeActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String theTime = String.format("%s:%d", hourOfDay, minute); btnChooseTime.setText(theTime); } }, 0, 0, true).show();
3. 单选按钮
4. 复选按钮
5. 下拉列表 Spinner
Spinner spinner; String[] dataSource = new String[] { "Spinner", "dataSource", "onCreate", "setContentView" }; spinner = (Spinner) findViewById(R.id.spinner); spinner.setAdapter(new ArrayAdapter<String>(SpinnerActivity.this, android.R.layout.simple_list_item_1, dataSource)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) { Log.d(TAG, "User choice = " + dataSource[position]); } @Override public void onNothingSelected(AdapterView<?> arg0) { } });
-----------------------------------------------------