1、下拉列表
android:layout_width="fill_parent"
android:layout_height="wrap_content">
public class MainActivity extends AppCompatActivity {
private List
private ArrayAdapter
private Spinner eduSpinner= null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//找到Spinner控件
eduSpinner = (Spinner)super.findViewById(R.id.eduSpinner);
eduSpinner.setPrompt("请选择您的学历:");
eduList = new ArrayList
eduList.add("大专");
eduList.add("本科");
eduList.add("硕士");
eduList.add("其他");
eduAdapter = new ArrayAdapter
eduAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
eduSpinner.setAdapter(eduAdapter);
}
}
2、日期选择器
btnChooseDate.setOnClickListener(newView.OnClickListener() {
@Override
public void onClick(View view) {
//呈现一个日期选择器:
new DatePickerDialog(ChoseADate.this, newDatePickerDialog.OnDateSetListener() {
@Override//当选择某一个日期会执行 onDateSet这个函数
public void onDateSet(DatePicker datePicker, inti, int i1, inti2) {
String date = String.format("%d年 - %d月 - %d日",i,i1+1,i2);
btnChooseDate.setText(date);
}
},2017,0,30).show();
}
});
}
3、时间选择器
@Override
public void onClick(View view) {
new TimePickerDialog(ChooseTime.this, newTimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, inti, int i1) {
btnChooseTime.setText(String.format("%d时%d分",i,i1));
}
},0,0,true).show();
}
4、单项选择
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.zhenzhoukeji.xialaselected.Single_choose">
//要放在RadioGroup 里面,可以放多个 RadioButton
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A.太平洋"/>
//mainActivity 中实现代码 判断是否选中
if (rbA.isChecked()){
Toast.makeText(Single_choose.this,"选择正确",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(Single_choose.this,"选择错误",Toast.LENGTH_SHORT).show();
}
5、多项选择
cb1.setOnCheckedChangeListener(this);
if (cb1.isChecked()){
str += cb1.getText() + ",";
}