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://bianchenghao.cn/37577.html