How to implement a custom AlertDialog View

前端 未结 11 991
悲&欢浪女
悲&欢浪女 2020-11-22 13:18

In the Android docs on AlertDialog, it gives the following instruction and example for setting a custom view in an AlertDialog:

If you want to display a
11条回答
  •  深忆病人
    2020-11-22 13:44

    It would make the most sense to do it this way, least amount of code.

    new AlertDialog.Builder(this).builder(this)
            .setTitle("Title")
            .setView(R.id.dialog_view)   //notice this setView was added
            .setCancelable(false)
            .setPositiveButton("Go", new DialogInterface.OnClickListener() {
                @Override 
                public void onClick(DialogInterface dialog, int id) {
                    EditText textBox = (EditText) findViewById(R.id.textbox);
                    doStuff();
                }
            }).show();
    

    For an expanded list of things you can set, start typing .set in Android Studio

提交回复
热议问题