gpt4 book ai didi

android - 无法关闭带有自定义按钮的对话框

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:25 28 4
gpt4 key购买 nike

如何关闭我的自定义对话框? .cancel().dismiss() 出现错误,好像它们没有在 native .setpositive/Negative button 之外解析/p>

已尝试 this回答但仍然无法正常工作..

这是我的对话代码:

public void showSettingsAlert(){

final AlertDialog.Builder alertdialog = new AlertDialog.Builder(mcontext);
LayoutInflater inflater = LayoutInflater.from(mcontext);
final View customView = inflater.inflate(R.layout.custom_gps,null);
alertdialog.setView(customView);
alertdialog.setCancelable(true);
FlatButton bouton_ok = (FlatButton)customView.findViewById(R.id.custom_ok_button);
FlatButton bouton_quitter = (FlatButton)customView.findViewById(R.id.custom_cancel_button);

bouton_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mcontext.startActivity(intent);


}
});
bouton_quitter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//to close the whole application :
finish();
System.exit(0);
}
});
alertdialog.show();
}

在我的主机 Activity 中,这是我检查 gps 是否启用的方式:

    protected void onResume() {
super.onResume();
gps = new GPSTracker(MainActivity.this);
// check if GPS enabled
if(gps.canGetlocation() ){
//stuff...
}else{
gps.showSettingsAlert();
}
}

最佳答案

AlertDialog.Builder 用于构建警报对话框。之后,create() 方法返回一个 AlertDialog 对象,它允许您调用 dismiss()。

AlertDialog.Builder builder = new AlertDialog.Builder(this);

LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.brush_opts_dialog,null);
builder.setView(dialogView);

closeBtn = (Button)dialogView.findViewById(R.id.close_btn);

final AlertDialog dialog = builder.create();

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

dialog.show();

关于android - 无法关闭带有自定义按钮的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305798/

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