Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add TextView and EditText using default AlertDialog programmatically
    primarykey
    data
    text
    <p>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:</p> <pre><code>// START Dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); TextView tv = new TextView(this); tv.setText(title); tv.setPadding(40, 40, 40, 40); tv.setGravity(Gravity.CENTER); tv.setTextSize(20); EditText et = new EditText(this); etStr = et.getText().toString(); alertDialogBuilder.setView(et); alertDialogBuilder.setTitle(title); alertDialogBuilder.setMessage("Input Student ID"); alertDialogBuilder.setCustomTitle(tv); if (isError) alertDialogBuilder.setIcon(R.drawable.icon_warning); // alertDialogBuilder.setMessage(message); alertDialogBuilder.setCancelable(false); // Setting Negative "Cancel" Button alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); // Setting Positive "Yes" Button alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (isError) finish(); else { Intent intent = new Intent( ChangeDeviceActivity.this, MyPageActivity.class); startActivity(intent); } } }); AlertDialog alertDialog = alertDialogBuilder.create(); try { alertDialog.show(); } catch (Exception e) { // WindowManager$BadTokenException will be caught and the app would // not display the 'Force Close' message e.printStackTrace(); } </code></pre> <p>For now, this is only an <code>EditText</code> with a message set by <code>alertDialogBuilder.setMessage("Input Student ID");</code> but I want to make this a <code>TextView</code> so I can center-justify it. How do I do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload