Reputation: 179
I am trying to change image of a list item on click.I have tried using view but on using it I am getting multiple items with changed image even though I just click on a single one.I am using a simplecursor adapter and code is same as given in this question:-changing image on listview at runtime in android.
And also I don't want to use a custom adapter.It will be really helpful if someone helps me in solving this problem just through simple adapter.
Current code
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
/*
imageView=(ImageView)l.getChildAt(position).findViewById(R.id.PlayPause);
imageView.setImageResource(R.drawable.pause);
*/
}
Upvotes: 1
Views: 2684
Reputation: 31
1- Do not use get child at when u are directly getting the child view as "View v" in the event.
2- you just need to call invalidate() method on the view once u set the new background resource.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
imageView=((ImageView)v)
imageView.setImageResource(R.drawable.pause);
imageView.invalidate();
}
While you should make your list using a simple cursor adapter with an imageview ---- :-
http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/
refer this link for that.
Upvotes: 1
Reputation: 1410
Why not use
ListView.OnItemClick(OnItemClickListener{})
http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html
Upvotes: 0