标签:android android-alertdialog alertdialog
如何解除我的自定义对话框?我在.cancel()和.dismiss()时遇到错误,好像它们没有在原生.setpositive / Negative按钮之外解析
尝试了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();
}
在我的主机活动中,这是我检查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,android-alertdialog,alertdialog 来源: https://codeday.me/bug/20190528/1172074.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。