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
| AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setIcon(R.mipmap.ic_launcher); builder.setTitle("水果"); final String[] hobbies = {"苹果", "香蕉", "菠萝", "橘子"};
builder.setMultiChoiceItems(hobbies, null, new DialogInterface.OnMultiChoiceClickListener() { StringBuffer stringBuffer = new StringBuffer(100); @Override public void onClick(DialogInterface dialog, int i, boolean isChecked) { if(isChecked) { stringBuffer.append(hobbies[i] + ", "); } Toast.makeText(MainActivity.this, "爱好为:" + stringBuffer.toString(), Toast.LENGTH_SHORT) .show(); } }); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { } }); builder.show();
|