android– 对话问题:在添加内容之前必须调用requestFeature()

android– 对话问题:在添加内容之前必须调用requestFeature(),第1张

概述我正在创建一个包含EditText的自定义对话框,以便我可以从用户那里获取文本数据:finalEditTextnewKey=(EditText)findViewById(R.id.dialog_result);AlertDialog.BuilderkeyBuilder=newAlertDialog.Builder(StegDroid.this);keyBuilder.setCancelable(false).setPosit

我正在创建一个包含EditText的自定义对话框,以便我可以从用户那里获取文本数据:

final EditText newKey = (EditText) findVIEwByID(R.ID.dialog_result);AlertDialog.Builder keyBuilder = new AlertDialog.Builder(StegDroID.this);keyBuilder.setCancelable(false).setPositivebutton("Try Again", new DialogInterface.OnClickListener() {    public voID onClick(DialogInterface dialog, int ID) {        Log.v("Dialog","New Key: "+newKey.getText().toString());    }}).setNegativebutton("Cancel", new DialogInterface.OnClickListener() {       public voID onClick(DialogInterface dialog, int ID) {            dialog.cancel();       }   });AlertDialog dialog = keyBuilder.create();dialog.setTitle("Decryption Failed");dialog.setContentVIEw(R.layout.decrypt_Failed_dialog);dialog.show();

但是我总是得到这个例外:

01-11 18:49:00.507: ERROR/AndroIDRuntime(3461): androID.util.AndroIDRuntimeException: requestFeature() must be called before adding content01-11 18:49:00.507: ERROR/AndroIDRuntime(3461):     at com.androID.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)01-11 18:49:00.507: ERROR/AndroIDRuntime(3461):     at com.androID.internal.app.AlertController.installContent(AlertController.java:199)01-11 18:49:00.507: ERROR/AndroIDRuntime(3461):     at androID.app.AlertDialog.onCreate(AlertDialog.java:251)...

在dialog.show()的行.我应该怎么做才能摆脱这个?

解决方法:

您需要在创建对话框之前设置自定义视图.如果您使用AlertDialog为您提供的默认正负按钮,则还需要使用setVIEw(VIEw)而不是setContentVIEw().

final EditText newKey = (EditText) findVIEwByID(R.ID.dialog_result);AlertDialog.Builder keyBuilder = new AlertDialog.Builder(StegDroID.this);keyBuilder.setCancelable(false).setPositivebutton("Try Again", new DialogInterface.OnClickListener() {    public voID onClick(DialogInterface dialog, int ID) {        Log.v("Dialog","New Key: "+newKey.getText().toString());    }}).setNegativebutton("Cancel", new DialogInterface.OnClickListener() {       public voID onClick(DialogInterface dialog, int ID) {            dialog.cancel();       }   });keyBuilder.setTitle("Decryption Failed");keyBuilder.setVIEw(getLayoutInflater().inflate(R.layout.decrypt_Failed_dialog, null));AlertDialog dialog = keyBuilder.create();dialog.show();
总结

以上是内存溢出为你收集整理的android – 对话问题:在添加内容之前必须调用requestFeature()全部内容,希望文章能够帮你解决android – 对话问题:在添加内容之前必须调用requestFeature()所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1097753.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存