Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try something like this:</p> <pre><code>ArrayList&lt;String&gt; myStringArray = ... // insert your code to get/create the array here ListView view = dialog.findViewById(R.id.listview1); ArrayAdapter&lt;String&gt; listAdapter = new ArrayAdapter&lt;String&gt; ( this, android.R.layout.simple_list_item_1, myStringArray); view.setAdapter(listAdapter); </code></pre> <p>Like so:</p> <pre><code>public class CustomDialougeListTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Context mContext = this; final Context context = this; Button button; ArrayList&lt;String&gt; myStringArray = ... // insert your code to get/create the array here ArrayAdapter&lt;String&gt; listAdapter = new ArrayAdapter&lt;String&gt; ( this, android.R.layout.simple_list_item_1, myStringArray); button = (Button) findViewById(R.id.button01); // add button listener button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // custom dialog final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.list); dialog.setTitle("List"); // set the custom dialog components - text, image and button TextView text = (TextView) dialog.findViewById(R.id.TextView01); text.setText("Test"); ListView view = dialog.findViewById(R.id.listview1); view.setAdapter(listAdapter); Button dialogButton = (Button) dialog.findViewById(R.id.Button01); // if button is clicked, close the custom dialog dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }); } } </code></pre>
 

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