1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| /**列表多选对话框**/ ArrayList<String> mChoices = new ArrayList<>(); final boolean initChoiceSets[]={false,false,false,false}; private void showMultiChoiceDialog() { final String[] items = { "items1","items2","items3","items4" }; AlertDialog.Builder multiChoiceDialog = new AlertDialog.Builder(this); multiChoiceDialog.setTitle("DiaLog Title"); multiChoiceDialog.setMultiChoiceItems(items, initChoiceSets, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { initChoiceSets[which] = isChecked; if (isChecked) { mChoices.add(items[which]); } else { String s = items[which]; Log.i("md"," findInterIdex(mChoices,s): "+findInterIdex(mChoices,s)); mChoices.remove(findInterIdex(mChoices,s)); } } }); multiChoiceDialog.setPositiveButton("Positive", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int size = mChoices.size(); String str = ""; for (int i = 0; i < size; i++) { str += mChoices.get(i) ; }
showToast("选择了 "+str); } }); multiChoiceDialog.show(); } public static int findInterIdex(List<String> nums, String target){ return Collections.binarySearch(nums,target); }
|