Android 的常用控件(下拉,日期,时间,单项,多项)
来源:互联网 发布:java 设置时区 编辑:程序博客网 时间:2024/06/12 01:32
1、下拉列表
<Spinner
android:id="@+id/eduSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Spinner>
public class MainActivity extends AppCompatActivity {
private List<CharSequence> eduList = null;
private ArrayAdapter<CharSequence> eduAdapter=null;
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<CharSequence>();
eduList.add("大专");
eduList.add("本科");
eduList.add("硕士");
eduList.add("其他");
eduAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,eduList);
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, inti1, 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, inti1) {
btnChooseTime.setText(String.format("%d时%d分",i,i1));
}
},0,0,true).show();
}
4、单项选择
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<TextView
//要放在RadioGroup里面,可以放多个 RadioButton
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rdA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A.太平洋"/>
</RadioGroup>
</LinearLayout>
//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() + ",";
}
- Android 的常用控件(下拉,日期,时间,单项,多项)
- 下拉列表,日期选择器,时间选择器,单项选择,多项选择
- Android—常用控件(四)日期/时间控件
- Android常用控件(按钮、选择框、日期时间控件)
- Android开发之四(五):常用控件之单项选择(RadioGroup和RadioButton)
- Android学习笔记17:单项选择RadioButton和多项选择CheckBox的使用
- Android里面主菜单里面设置菜单列表,单项选择,多项选择的实现
- android时间日期控件
- android日期时间控件
- Android实现自定义的 时间日期 控件
- Android 滚动的时间日期选择控件
- Android日期时间控件的学习笔记
- android 时间日期控件的使用
- Androi常用日期时间控件
- android--日期时间控件(十二)
- Android开发之四(六):常用控件之多项选择(CheckBox)
- 单项选择RadioButton和多项选择CheckBox的使用
- 单项选择RadioButton和多项选择CheckBox的使用
- 丰声共享文件方法
- jfinal重温
- index、noindex、follow、nofollow的使用说明
- HDU4135 Co-prime【容斥原理】3方法
- MySQL数据表导入Excel模板
- Android 的常用控件(下拉,日期,时间,单项,多项)
- Vue.js学习笔记:v-if条件渲染与v-show区别
- 学习笔记
- C
- 更改Tomcat日志路径
- 2017全国大学生信安赛 easyheap
- 影响关键词排名稳定的因素有哪些?
- 前端基础学习之CSS样式
- 【bzoj1334】[Baltic2008]Elect