Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had to do something like this recently, hopefully this might help you out:</p> <pre><code> // Create a ScrollView so the dialog can scroll ScrollView scrollView = new ScrollView(getActivity()); scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create layout for the controls in the dialog LinearLayout lay = new LinearLayout(getActivity()); lay.setOrientation(LinearLayout.VERTICAL); lay.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // Create a TextView to add to the dialog TextView productNameLabel = new TextView(getActivity()); productNameLabel.setText("Some text"); productNameLabel.setGravity(Gravity.CENTER); productNameLabel.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); // Add the views to the layout lay.addView(productNameLabel); // Add the layout to the scrollview scrollView.addView(lay); // Create the dialog final AlertDialog.Builder b = new AlertDialog.Builder(getActivity()) .setTitle("Dialog Title") .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do something when OK is clicked } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do something when Cancel is clicked } }); // Tell the dialog to use the ScrollView b.setView(scrollView); // Show the dialog b.create().show(); </code></pre> <p>It's probably not the best way of doing things, but I'm new to Android and what I've done works :)</p>
 

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