- public void click3(View v){
- AlertDialog.Builder builder = new Builder(this);
- builder.setTitle("请选择爱吃的水果");
- final String[] items = {"苹果","栗子","番茄","香蕉"};<font color="#ff0000">
- <b> final boolean[] result=new boolean[]{false,true,true,false};</b></font>
- builder.setMultiChoiceItems(items, result, new OnMultiChoiceClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which, boolean isChecked) {
- // TODO Auto-generated method stub
- Toast.makeText(getApplicationContext(), items[which], 0).show();
- <b> result[which]=isChecked</b>; <font color="#ff0000" size="3"><b>result是final的数组 为啥可以修值?</b></font>
- }
- });
- builder.setPositiveButton("提交", new OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- StringBuffer buff = new StringBuffer();
- for(int i=0;i<result.length;i++){
- if(result[i]){
- buff.append(items[i]);
- }
- }
- Toast.makeText(getApplicationContext(), "您选择了"+buff.toString(), 0).show();
- }
- });
复制代码
|
|