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();

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

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