Dialog problem: requestFeature() must be called before adding content

前端 未结 9 505
名媛妹妹
名媛妹妹 2020-12-31 02:39

I\'m creating a custom dialog containing an EditText so that I can get text data from the user:

final EditText newKey = (EditText) findViewById(R.id.dialog_r         


        
9条回答
  •  醉梦人生
    2020-12-31 03:35

    You need to set the custom view before creating the dialog. Also you need to use setView(View) instead of setContentView() if you are using the default positive and negative buttons provided for you by the AlertDialog.

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

提交回复
热议问题