Edit:
The solution is probably simple. Take a boolean array globally like this.
private final boolean[] selectedstates;
And initialize it with the size of your list in your constructor
selectedstates= new boolean[yourlist.size()];
And aside from listening to onclick as shown
yourbutton.setSelected(selectedstates[position]);
I hope this helps you
try it
Take a custom selector with two different state images for selection and without selection
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/pause_button" android:state_selected="true" /> <item android:drawable="@drawable/play_button" /> </selector>
1.Create a global variable
Imageview previous;
in your user adapter and initialize it in the constructor where you get the content
previous=new ImageView(context);
Add to your getView () method you'll probably have an onclickListener for your Imageview do this
imagPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ImageView current=((ImageView)v); current.setSelected(true); previous.setSelected(false); previous=current; } });
This will work, I was sure because I used it in my application. Hope this helps you.
source share