Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to implement your own Adapter. My way is to also define an object which "represents" a view.</p> <p>Below, there is a very simple example with two <code>TextViews</code> to fit your needs.</p> <p>The object which represents a view (a row in the ListView) :</p> <pre><code>public class CustomObject { private String prop1; private String prop2; public CustomObject(String prop1, String prop2) { this.prop1 = prop1; this.prop2 = prop2; } public String getProp1() { return prop1; } public String getProp2() { return prop2; } } </code></pre> <p>Next the custom adapter :</p> <pre><code>public class CustomAdapter extends BaseAdapter { private LayoutInflater inflater; private ArrayList&lt;CustomObject&gt; objects; private class ViewHolder { TextView textView1; TextView textView2; } public CustomAdapter(Context context, ArrayList&lt;CustomObject&gt; objects) { inflater = LayoutInflater.from(context); this.objects = objects; } public int getCount() { return objects.size(); } public CustomObject getItem(int position) { return objects.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if(convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate(R.layout.your_view_layout, null); holder.textView1 = (TextView) convertView.findViewById(R.id.id_textView1); holder.textView2 = (TextView) convertView.findViewById(R.id.list_id_textView2); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.textView1.setText(objects.get(position).getprop1()); holder.textView2.setText(objects.get(position).getprop2()); return convertView; } } </code></pre> <p>Now you can define and set your adapter in your activity :</p> <pre><code>ArrayList&lt;CustomObject&gt; objects = new ArrayList&lt;CustomObject&gt;(); CustomAdapter customAdapter = new CustomAdapter(this, objects); listView.setAdapter(customAdapter); </code></pre> <p>Now you only have to manage your CustomObject's in the objects list. Don't forget to invoke <code>customAdapter.notifyDataSetChanged()</code> when you want repercute modifications on the ListView.</p>
    singulars
    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