如何使用自定义按钮设置/清除警报对话框中的多重项目?

时间:2012-10-08 07:03:04

标签: android alertdialog custom-component android-alertdialog onclicklistener

我做了一个小的Android应用程序。在其中我需要一个多重的AlertDialog。 但我需要自定义按钮(当点击按钮时,它会隐藏,我们可以在这个地方看到另一个按钮)。我知道了。 但是当我试图通过点击我的自定义按钮设置所有多选项时,我不知道该怎么做。因为他们的onclicklistener中的自定义按钮没有

 public void onClick(DialogInterface dialog, int index, boolean status)
 {                        

 }   

我不知道如何进入对话框项目。 我希望我的问题很清楚) 添加我的所有代码:

protected Dialog onCreateDialog(int id) {

    // AlertDialog.Builder
    adb = new AlertDialog.Builder(this);

    // multichoice from array and array of checked items
    adb.setTitle("Категории");
    adb.setMultiChoiceItems(category, category_chkd,
            new DialogInterface.OnMultiChoiceClickListener() {

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

                }
            });

    // dialog buttons from category_buttons.xml
    cat_view = (RelativeLayout) getLayoutInflater().inflate(
            R.layout.category_buttons, null);
    adb.setView(cat_view);

    cat_fill_btn = (Button) cat_view
            .findViewById(R.id.category_fill_button);
    cat_clean_btn = (Button) cat_view
            .findViewById(R.id.category_clean_button);
    cat_ok_btn = (Button) cat_view.findViewById(R.id.category_ok_button);


    //AlertDialog
    alert = adb.create();
    //button Ok
    cat_ok_btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            alert.cancel();

        }
    });

    //  button to clear the list
    cat_clean_btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            cat_fill_btn.setVisibility(View.VISIBLE);
        }
    });

    // button to fill the list
    cat_fill_btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            cat_fill_btn.setVisibility(View.INVISIBLE);

        }
    });

    return alert;

}

0 个答案:

没有答案