How to make a edittext box in a dialog

后端 未结 8 1884
借酒劲吻你
借酒劲吻你 2020-11-28 01:34

I am trying to make a edittext box in a dialog box for entering a password. and when I am doing I am not able to do. I am a beginner in it. Please help me in this.



        
8条回答
  •  感动是毒
    2020-11-28 01:45

    Simplest of all would be.

    • Create xml layout file for dialog . Add whatever view you want like EditText , ListView , Spinner etc.

      Inflate this view and set this to AlertDialog

    Lets start with Layout file first.

    
    
    
    
        
    
    
    

    final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null);
    AlertDialog alertDialog = new AlertDialog.Builder(ct).create();
    alertDialog.setTitle("Your Title Here");
    alertDialog.setIcon("Icon id here");
    alertDialog.setCancelable(false);
    Constant.alertDialog.setMessage("Your Message Here");
    
    
    final EditText etComments = (EditText) view.findViewById(R.id.etComments);
    
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
    
        }
    });
    
    
    alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss()
        }
    });
    
    
    alertDialog.setView(view);
    alertDialog.show();
    

提交回复
热议问题