Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You must declare a custom Adapter to do that.</p> <p>This tutorial helped me out a lot: <a href="http://www.vogella.de/articles/AndroidListView/article.html#listview_adaptermodel" rel="nofollow">http://www.vogella.de/articles/AndroidListView/article.html#listview_adaptermodel</a></p> <p>Here is a snippet from one of my projects. It alternates between two images inside a ImageView when clicked.</p> <pre><code> private class EventsAdapter extends ArrayAdapter&lt;Eveniment&gt; { private ArrayList&lt;Eveniment&gt; items; ... public OnClickListener goingClickListener2= new OnClickListener() { public void onClick(View v) { ((ImageView)v).setImageResource(R.drawable.going1); v.setOnClickListener(goingClickListener); } }; public OnClickListener goingClickListener = new OnClickListener() { public void onClick(View v) { ((ImageView)v).setImageResource(R.drawable.going2); v.setOnClickListener(goingClickListener2); } }; @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.listitemlayout, null); } if (items==null) return v; Eveniment ev = items.get(position); if (ev != null) { //init for each listItem TextView tv_Titlu = (TextView) v.findViewById(R.id.tv_Titlu); TextView tv_eventBody = (TextView)v.findViewById(R.id.tv_eventBody); ImageView iv_EventPic = (ImageView)v.findViewById(R.id.iv_eventPic); ImageView iv_going = (ImageView)v.findViewById(R.id.iv_going); iv_going.setOnClickListener(goingClickListener);//setting the onClickListener tv_Titlu.setText(ev.getEvent()); ... //other initialization for each view in my layout } return v; } </code></pre> <p>In the above example getView() is called for each listItem. I get access to my ImageVeiw by calling findViewById() on the view v ( a RelativeLayout inside each listItem )</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. 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.
 

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