关键部分代码如下

1、Spinnner

在布局文件中:

  <TableRow                    android:layout_width="match_parent"                    android:layout_height="wrap_content" >                    <Spinner                        android:id="@+id/sp_select_leave_type"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:layout_marginLeft="85dp" />                </TableRow>

定义对象:

private Spinner mSpinnerSelectLeaveType;//选择请假类型

获得对象后绑定监听事件:

mSpinnerSelectLeaveType.setOnItemSelectedListener(new OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view,int position, long id) {//获得每项选中的数据mleaveType= getApplicationContext().getResources().getStringArray(R.array.leave_type)[position];}@Overridepublic void onNothingSelected(AdapterView<?> parent) {Toast.makeText(getApplicationContext(), "确认是否正确选择", 500).show();}});


给spinnner绑定数据关键代码如下:

/**
* 为请假人部门spinner绑定数据
*/
private void setDepartmentAdapter(){
mcontentDepartment=getApplicationContext().getResources().getStringArray(R.array.leave_department);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, R.layout.spinner_item, mcontentDepartment);
mSpinnerSelectDepartment.setAdapter(adapter);
}


mcontentDepartment=getApplicationContext().getResources().getStringArray(R.array.leave_department);这段代码是获取res/values中的strings中获取对应的数据:

 <string-array name="leave_type">        <item >事假</item>        <item >婚假</item>        <item >病假</item>    </string-array>

每个数据显示的布局:

<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:textColor="#f00"    android:textSize="15sp"    android:padding="10dp"    >    </TextView>

运行结果:



2、数值选择器




更多相关文章

  1. android 不销毁当前activity,返回上一层,亲测有效
  2. Android(安卓)SDK 源码下载,eclipse关联代码
  3. android 输入对话框 确认对话框
  4. Android(安卓)G711A 音频编解码,去除“吱吱”电流声,附上so下载地
  5. Android(安卓)使用RecyclerView的方法
  6. Android(安卓)获取验证码倒计时实现
  7. [置顶] Android(安卓)IPC 通讯机制源码分析【下】
  8. Android(安卓)设置Dalog大小
  9. Android(安卓)【将图片网址Url转化为Bitmap工具类】

随机推荐

  1. Android,开源还是封闭?
  2. 10款最佳Android快速应用程序切换
  3. Android视频开发浅析
  4. Android中文合集 最终版
  5. 安卓巴士总结了近百个Android优秀开源项
  6. android的原理,为什么我们不需要手动关闭
  7. Android(安卓)Build 系统详解
  8. Android读写文件正确实行方法介绍
  9. 获取android设备 id
  10. Android开发艺术探索——第十一章:Android