自定义弹出式对话框(与ListView的结合)
??
核心代码:
?
case R.id.button:LayoutInflater inflater = LayoutInflater.from(this);// 渲染器View customdialog2view = inflater.inflate(R.layout.customdialog2,null);AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("自定义对话框");// builder.setTitle("意见模版");builder.setView(customdialog2view);builder.setPositiveButton("确定",new DialogInterface.OnClickListener() //{// 确定按钮的单击事件public void onClick(DialogInterface dialog, int which) {for (int i = 0; i < isSelect.length; i++) {if (isSelect[i]) { // 如果该选项被选中result = result + opition[i] + "、";}}try {etEditText.setText(result.substring(0, result.length() - 1));} catch (Exception e) {}result = "";}});builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub}});ListView listView = (ListView) customdialog2view.findViewById(R.id.lv);listView.setAdapter(adapter);listView.setItemsCanFocus(false);listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);listView.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {ViewHolder vHollder = (ViewHolder) view.getTag();// 在每次获取点击的item时将对于的checkbox状态改变,同时修改map的值。vHollder.cBox.toggle();// 反转当前视图的选中状态if (vHollder.cBox.isChecked() == true) {isSelect[position] = true;} else {isSelect[position] = false;}MyAdapter.isSelected.put(position, vHollder.cBox.isChecked());}});opinionsDialog = builder.create();opinionsDialog.show();break;
?