要求:用Dialog对话框显示一个列表,并实现其点击效果
代码:
private ListView lv_list; private String deleteName; private AlertDialog.Builder builder; private Dialog dialog; private void showDialog() { /** * 创建Dialog,参数为当前环境与样式。 */ builder = new AlertDialog.Builder(this); View view = LayoutInflater.from(Managr_BanCi_List.this).inflate( R.layout.dialog_list, null); TextView tv_text = (TextView) view.findViewById(R.id.tv_dialog_list); tv_text.setText("请选择指派到其他班次的员工"); lv_list = (ListView) view.findViewById(R.id.lv_dialog_list); builder.setView(view); builder.setCancelable(false); // 设置适配器,适配器参数分别为:当前环境、listview中的item、item中的textview、textview所需的数据数据 lv_list.setAdapter(new ArrayAdapter<String>(Managr_BanCi_List.this, R.layout.listview_item, R.id.tv_listview_item, data_Delete)); // 为listview中的item设置点击事件 lv_list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { biaoshi = true; Intent intent = new Intent(Managr_BanCi_List.this, Manager_Add.class); DeleteBanC_PeoPleName deleteBanC_PeoPleName = (DeleteBanC_PeoPleName) treeMap_Delete .get(data_Delete[position]); intent.putExtra("companyId", getIntent().getExtras().getString("id")); deleteName = deleteBanC_PeoPleName.name; intent.putExtra("name", deleteBanC_PeoPleName.name);// 姓名 intent.putExtra("dapart", deleteBanC_PeoPleName.dapart);// 部门 intent.putExtra("id", deleteBanC_PeoPleName.id);// 员工 intent.putExtra("loginname", deleteBanC_PeoPleName.loginname);// 登录用户名 intent.putExtra("phone", deleteBanC_PeoPleName.phone);// 手机 intent.putExtra("pwd", deleteBanC_PeoPleName.pwd);// 密码 intent.putExtra("biaoshi", biaoshi);// 员工转移班次 startActivityForResult(intent, 10); } }); // 显示 dialog = builder.show(); }
关闭:
dialog.dismiss();
本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1757524
原文地址:http://liuxudong1001.blog.51cto.com/10877072/1757524