AlertDialog.Builder setPositiveButton 点击时不关闭dialog

AlertDialog.Builder setPositiveButton 点击时不关闭dialogAlertDialog.BuildersetPositiveButton 与 setNegativeButton点击时都会自动关闭dialog,但是文本控制不想其关闭两种方法①:LayoutInflater inflater=LayoutInflater.from(mActivity);Viewview=inflater.inflate(R.layout.

大家好,又见面了,我是你们的朋友全栈君。

AlertDialog.Builder setPositiveButton  与 setNegativeButton 点击时都会自动关闭 dialog,但是 文本控制 不想其关闭 两种方法

①:

LayoutInflater  inflater = LayoutInflater.from(mActivity);

View view = inflater.inflate(R.layout.dialog_chang_script_id, null);


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


builder.setTitle(mActivity.getString(R.string.script_btn_change_orider_id_titel));


builder.setView(view);


final EditText et = (EditText) view.findViewById(R.id.et_script_or_id);


builder.setNegativeButton(mActivity.getString(R.string.script_btn_cancel), null);


builder.setPositiveButton(mActivity.getString(R.string.script_btn_yes), null);


builder.create();


final AlertDialog dialog = builder.create();


dialog.show();



dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() {





@Override


public void onClick(View v) {


if(TextUtils.isEmpty(et.getText())){


viewInterface.toast(mActivity.getString(R.string.script_orider_id_can_not_null));


et.setError(mActivity.getString(R.string.script_orider_id_can_not_null));


}else {


SPrefHookUtil.putSettingStr(mActivity, SPrefHookUtil.KEY_SETTING_ORDER_ID, et.getText().toString());


getIsScriptExist(getOriderId());



dialog.dismiss();


}


}


});

}

② 反射

LayoutInflater layoutInflater = LayoutInflater.from(context);
View dialogView = layoutInflater.inflate(R.layout.dialog_edit_text,null);
final EditText et = (EditText) dialogView.findViewById(R.id.et_dialog_text);

Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.liucun_dialog_set_total_title));
builder.setView(dialogView);
builder.setNegativeButton(context.getString(R.string.liucun_dialog_btn_cancel), null);
builder.setPositiveButton(context.getString(R.string.liucun_dialog_btn_ok),new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {

String count = et.getText().toString();
Logger.i(“==count==”+count);
if (TextUtils.isEmpty(count)) {

et.setError(context.getString(R.string.liucun_tip_total_count_not_null));
viewInterface.toast(context.getString(R.string.liucun_tip_total_count_not_null));
try {

Field field = dialog.getClass().getSuperclass().getDeclaredField(“mShowing”);
field.setAccessible(true);
field.set(dialog, false);
Logger.i(“==field==”+field);
} catch (Exception e) {

e.printStackTrace();
Logger.i(“==field=Exception=”+e);
}

} else {

int integer = Integer.parseInt(count);
boolean result = SPrefHookUtil.putSettingInt(context,SPrefHookUtil.KEY_SETTING_RUN_TIMES,integer);
if (result) {

viewInterface.toast(context.getString(R.string.liucun_tip_total_count_set_ok));
int totalCount = SPrefHookUtil.getSettingInt(context,SPrefHookUtil.KEY_SETTING_RUN_TIMES,SPrefHookUtil.D_SETTING_RUN_TIMES);
viewInterface.setTotalCountText(totalCount);
} else {

viewInterface.toast(context.getString(R.string.liucun_tip_total_count_set_err));
}
dialog.dismiss();
}
}
});
final AlertDialog dialog = builder.create();

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149263.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月16日 下午6:16
下一篇 2022年6月16日 下午6:16


相关推荐

  • git安装教程 windows10_灯保姆安装公司

    git安装教程 windows10_灯保姆安装公司git安装与使用的保姆级教程,图文齐全,一步一步教,小白看了都说好~,安装、使用、创建仓库、同步代码、检查代码、创建分支、合并主分支等等…

    2025年8月30日
    5
  • Laravel框架_php laravel框架

    Laravel框架_php laravel框架laravel框架一、laravel简介laravel是一套优雅简介的PHP开发框架,受欢迎程度非常之高,功能强大,工具齐全;https://www.jianshu.com/p/206592c78113二、简单介绍1、laravel是基于mvc模式的php框架,m——模型层,v——视图层,c——控制器层;以下为laravel框架的目录文件,框出来的文件目录将在后续中用到:2、什么是MV…

    2025年8月23日
    3
  • Android语音采集两种方式MediaRecorder和AudioRecord

    Android语音采集两种方式MediaRecorder和AudioRecord

    2021年8月31日
    79
  • c#attribute应用_sql float

    c#attribute应用_sql float今天研究了一下C#中的Attributes的用法,感觉很有用,现总结以下:    在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用。      即在后台页面加载时,调用JS方法。语法格式有两种,如下:      第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);      如:一个按钮控件Butto

    2026年4月13日
    3
  • SpringBoot2-[SpringBoot优缺点、微服务理解、版本仲裁]

    SpringBoot2-[SpringBoot优缺点、微服务理解、版本仲裁]??‍?博主介绍:大家好,我是芝士味的椒盐,一名在校大学生,热爱分享知识,很高兴在这里认识大家??擅长领域:Java、大数据、运维、电子??如果本文章各位小伙伴们有帮助的话,?关注+??点赞+?评论+?收藏,相应的有空了我也会回访,互助!!!?另本人水平有限,旨在创作简单易懂的文章,在文章描述时如有错,恳请各位大佬指正,在此感谢!!!文章目录Spring.ioSpring5重大升级SpringBoot优点SpringBoot缺点微服务SpringBoot官方文档Maven设置SpringBo..

    2026年4月14日
    4
  • idea激活插件破解方法

    idea激活插件破解方法,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月14日
    126

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号