Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to do it through an <code>ArrayAdapter</code> which will adapt your ArrayList (or any other collection) to your items in your layout (ListView, Spinner etc.).</p> <p>This is what the <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html" rel="noreferrer">Android developer guide</a> says:</p> <blockquote> <p>A <code>ListAdapter</code> that manages a <code>ListView</code> backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single <code>TextView</code>. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a <code>TextView</code> in the larger layout resource. </p> <p>However the <code>TextView</code> is referenced, it will be filled with the <code>toString()</code> of each object in the array. You can add lists or arrays of custom objects. Override the <code>toString()</code> method of your objects to determine what text will be displayed for the item in the list. </p> <p>To use something other than <code>TextViews</code> for the array display, for instance <code>ImageViews</code>, or to have some of data besides <code>toString()</code> results fill the views, override <code>getView(int, View, ViewGroup)</code> to return the type of view you want.</p> </blockquote> <p>So your code should look like:</p> <pre><code>public class YourActivity extends Activity { private ListView lv; public void onCreate(Bundle saveInstanceState) { setContentView(R.layout.your_layout); lv = (ListView) findViewById(R.id.your_list_view_id); // Instanciating an array list (you don't need to do this, // you already have yours). List&lt;String&gt; your_array_list = new ArrayList&lt;String&gt;(); your_array_list.add("foo"); your_array_list.add("bar"); // This is the array adapter, it takes the context of the activity as a // first parameter, the type of list view as a second parameter and your // array as a third parameter. ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;String&gt;( this, android.R.layout.simple_list_item_1, your_array_list ); lv.setAdapter(arrayAdapter); } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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