想在textdialog中将textview置于Multi选项之上

时间:2017-10-11 16:14:27

标签: java android android-layout android-alertdialog

我正在尝试创建一个对话框,其顶部是时钟,底部是星期几。但是我无法将时钟放在setMultiChoiceItems之上。

public void onFabClick(){


    clock = new TextView(this);

    //Setting Listener for Clock.
    clock.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Calling Time picker
            timepicker();

        }
    });

    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setView(clock);
    final String[] Colors = new String[]{
            "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
    };
    final ArrayList<Integer> selectedItems = new ArrayList<Integer>();
    final boolean[] preCheckedItems = new boolean[]{
            true,true,true,true,true,true,true
    };
    adb.setMultiChoiceItems(Colors, preCheckedItems, new DialogInterface.OnMultiChoiceClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked){
//Insert Code here
    });

    adb.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which){
           //Test
            Log.d("alertdialog!!!!","Clicked OK");
        }
    });

    adb.setNeutralButton("Cancel", null});

    adb.show();
}

1 个答案:

答案 0 :(得分:0)

您可以创建包含所有项目的布局文件,并根据您的需要订购。然后就用吧 .setView(view); AlertDialog.Builder()

{{1}}