AlertDialog.Builder类型中的方法setMultiChoiceItems(int,boolean [],DialogInterface.OnMultiChoiceClickListener)不适用

时间:2015-05-18 12:07:43

标签: android

我正在尝试在我的onNewIntent方法中为任何整数ArrayList构建一个动态对话框窗口,例如[1,9,13],但我在此行builder.setMultiChoiceItems出现此错误“

  

方法setMultiChoiceItems(int,boolean [],   DialogInterface.OnMultiChoiceClickListener)中的类型   AlertDialog.Builder不适用于参数   (ArrayList,null,new   DialogInterface.OnMultiChoiceClickListener(){})

我感谢任何帮助。

onNewIntent方法:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    setIntent(intent);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {

        ArrayList<Integer> routeList = extras
                .getIntegerArrayList("stop_route");
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle("Select");

        builder.setMultiChoiceItems(routeList, null, new DialogInterface.OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {


            }
        });
        builder.setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
        builder.setNegativeButton(android.R.string.cancel,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });


        builder.create();
        builder.show();

    }

}

1 个答案:

答案 0 :(得分:0)

您可以使用

public AlertDialog.Builder setMultiChoiceItems (CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)

只需将您的ArrayList<Interger>转换为CharSequence[]

转换:

ArrayList<Integer> routeList = extras.getIntegerArrayList("stop_route");
CharSequence charSequence [] = new CharSequence[routeList.size()];
for(int i = 0, size = routeList.size(); i < size; i++){
    charSequence[i] = String.valueOf(routeList.get(i));
}

builder.setMultiChoiceItems(charSequence, null, new Dia ..........