【问题标题】:Modify LinearLayout content when dialog is clicked单击对话框时修改 LinearLayout 内容
【发布时间】:2013-08-14 15:51:57
【问题描述】:

我创建了一个LinearLayout,其中包含一组复选框。如果单击每个复选框,则会生成一个对话框,如下所示:

checkBox.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyActivity.this);
        alertDialog.setTitle("title");
        alertDialog.setMessage("dialog");
        alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {

            }
        });
        // Similarly for the NegativeButton
        alertDialog.show();
    }
});

现在,我想删除复选框,以防有人在警报对话框中按下肯定按钮。谁能建议我怎么做?

提前致谢。

【问题讨论】:

    标签: android view checkbox interface


    【解决方案1】:

    要删除您可以使用的任何视图

    ll.removeView(view)// to remove particular view
    ll.removeViewAt(position);// to remove view from particular position
    

    在您的 xml 和代码中使用 android:onClick="onCheckboxClicked"

    public void onCheckboxClicked(View v) => 你得到了对复选框的引用

    【讨论】:

    • 当然,但这里缺少的是对视图的引用。我在 AlertDialog 对象的 onClick 方法中。如何访问对视图的(外部)引用(即复选框)?
    • MyActivity.this.theNameOfLinearLayout 和 MyActivity.this.theNameOfCheckBox
    • 此外,假设复选框位于复选框列表中。是否可以将其位置传递给对话框?
    • 在你的 xml 和代码中使用 android:onClick="onCheckboxClicked": public void onCheckboxClicked(View v) => 你得到一个复选框的引用 ;-)
    猜你喜欢
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    相关资源
    最近更新 更多