0

** Emulator 不显示 Multichoice item("Google","Apple","Ms","Samsumg","Nokia").... 它不执行 setmultiitemsselected 函数谁能帮我找出解决方案?**

   
    ***My Program***

    public class DialogActivity extends Activity {
    CharSequence[] items = {"Google","Apple","Ms","Samsumg","Nokia"};
        boolean[] itemcheck = new boolean[items.length];
        public void onClick(View v) {
            showDialog(0);
        }

        @Override
        protected Dialog onCreateDialog(int id) {
        Dialog d = null;
            switch (id) {
            case 0:
            AlertDialog.Builder ab = new AlertDialog.Builder(this);
            ab.setIcon(R.drawable.fb);
            ab.setTitle("Facebook Dialog");
            ab.setMessage("Successfully Logged");
            ab.setPositiveButton("OK",new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(getApplicationContext(), "OK Clicked", Toast.LENGTH_LONG).show();}
            });
      ab.setMultiChoiceItems(items, itemcheck, 
                  new DialogInterface.OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog,
                    int which, boolean isChecked) {
                Toast.makeText(getBaseContext(), items[which] + (isChecked? "Checked" :"Unchecked"), Toast.LENGTH_SHORT).show();
                }
        });
            d = ab.create();
            }
            return d;
        }  }

    ***Xml File***
         

    
4

2 回答 2

0

“未执行 setmultiitemselected 函数”是什么意思?

创建一个最简单的方法AlertDialog是:

CharSequence[] items = {"Google","Apple","Ms","Samsumg","Nokia"};
boolean[] itemcheck = new boolean[items.length];

new AlertDialog.Builder(this)
.setIcon(R.drawable.fb)
.setTitle("Facebook Dialog")
.setMessage("Successfully Logged")
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(getApplicationContext(), "OK Clicked", Toast.LENGTH_LONG).show();
    }
})
.setMultiChoiceItems(items, itemcheck, new DialogInterface.OnMultiChoiceClickListener() {
    @Override
    public void onClick(DialogInterface dialog,
        int which, boolean isChecked) {
        Toast.makeText(getBaseContext(), items[which] + (isChecked? "Checked" :"Unchecked"), Toast.LENGTH_SHORT).show();
    }
})
.show();

尽管数组itemcheck在您当前的实现中没有任何意义!

于 2013-04-07T14:31:18.523 回答
0

问题是,setMultiChoiceItems不能setMessage一起使用。如果您指定消息,则不会出现复选框。

于 2015-06-21T19:06:51.670 回答