How to add TextView and EditText using default AlertDialog programmatically

前端 未结 3 1442
别跟我提以往
别跟我提以往 2021-02-14 13:51

I\'ve been trying to add two elements in a default AlertDialog but I can\'t seem to make it work. Here\'s my code:

// START Dialog
    AlertDialog.Builder alertD         


        
3条回答
  •  南旧
    南旧 (楼主)
    2021-02-14 14:15

    Make one .xml file which include whatever view you want like below.

    
    
    
    
    
    
    
        
    
    

    After that in your .java file implements following code.

    View view = View.inflate(this, R.layout.yourxmlname, null);
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    // Now set the dialog's content
    alert.setContentView(view);
    

    Hope it helps you.

提交回复
热议问题