gpt4 book ai didi

android - 单击按钮时关闭自定义警报对话框

转载 作者:IT老高 更新时间:2023-10-28 21:57:37 25 4
gpt4 key购买 nike

我无法关闭警报对话框。我正在使用布局充气器来制作对话框,所以我不确定在完成后我将如何关闭它。代码如下:

AlertDialog.Builder dialog = new AlertDialog.Builder(AddData.this);
DialogInterface dia = new DialogInterface();

//Create a custom layout for the dialog box
LayoutInflater inflater = (LayoutInflater)AddData.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.add_rep_1_set, parent, false);

TextView title = (TextView)layout.findViewById(R.id.rep_1_title);
Button add_item = (Button)layout.findViewById(R.id.add_button);

add_item.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//Need this to close the alert dialog box
}
});

title.setText(workout_items[position]);
dialog.setView(layout);
dialog.show();

我无法调用完成,因为这会关闭启动警报对话框的 ListView ,并且我无法使用 dialog.dismiss 调用。

你认为我应该怎么做才能解决这个问题?

最佳答案

AlertDialog.Builder dialog = new AlertDialog.Builder(AddData.this);
DialogInterface dia = new DialogInterface();

//Create a custom layout for the dialog box
LayoutInflater inflater = (LayoutInflater)AddData.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.add_rep_1_set, parent, false);

TextView title = (TextView)layout.findViewById(R.id.rep_1_title);
Button add_item = (Button)layout.findViewById(R.id.add_button);

title.setText(workout_items[position]);
dialog.setView(layout);

AlertDialog alertDialog = dialog.create();

add_item.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
alertDialog.dismiss();
}
});


alertDialog.show();

关于android - 单击按钮时关闭自定义警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5713312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com