I am developing a soundboard application in which I use Listview Activity. But since Listview of Android has the property of recycling its listviews, the changes I make to the selected textview gets reflected in all the pages while scrolling the listview. I don't want this to happen. So how do I handle it properly. If somebody can help me out with code snippet, it will be really helpful and I appreciate your effort. Thank you!
Edit: Hope this will explain better
My class extends ListActivity and the listview is as follows
[Image] [Text]
[Image] [Text]
[Image] [Text]
Now when the user clicks on any textview, I need to change the image of that textview. I implement that by the following code.
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
TextView tv = (TextView) view;
//Here I change the image with tv as reference
final Resources res = getBaseContext().getResources();
final Drawable myImage = res.getDrawable(R.drawable.pause);
// myImage.
final Drawable myImage1 = res.getDrawable(R.drawable.play);
tv.setCompoundDrawablesWithIntrinsicBounds(myImage, null, null, null);
MediaPlayer.OnCompletionListener listener = new MediaPlayer.OnCompletionListener(){
public void onCompletion(MediaPlayer mp) {
tv.setCompoundDrawablesWithIntrinsicBounds(myImage1, null, null, null);
}
};
}
Short answer: Have your list's adapter handle updates to the data to render the changes correctly. That is, override/edit the getView() method if necessary to know how to handle the data change, edit the data underlying your Adapter, call notifyDataSetChanged(), and let those data changes propagate down to views when getView gets called. Right now, you're probably hand-modifying the views without changing the underlying data, which is a violation of MVC patterns regardless of the view-recycling bits.
Given how generically you asked the question, though, it'd be rather difficult to give you a code sample that fits your particular case.