Hi I am working with android . I had created a custom grid view with an imageview to add this item as favorite and when click on that item its background chaged as selected.Now the problem is that I can select all these favorite button and when I scroll down its selector position is changed and when I click on one item other item is automatically get selected. How can i solve this problem please help me. Thanks in advance :)
here is my adapter class
![public class CustomGrid extends BaseAdapter{
private Context mContext;
private final String\[\] web1;
private final int\[\] Imageid;
public CustomGrid(Context c,String\[\] web,int\[\] Imageid ) {
mContext = c;
this.Imageid = Imageid;
this.web1 = web;
}
@Override
public int getCount() {
return web1.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView button01;
View v;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(R.layout.grid_single, parent, false);
} else {
v = convertView;
}
TextView text = (TextView)v.findViewById(R.id.grid_text);
text.setText(web1\[position\]);
ImageView image = (ImageView)v.findViewById(R.id.grid_image);
image.setBackgroundResource(Imageid\[position\]);
button01 = (ImageView)v.findViewById(R.id.star);
button01.setOnClickListener(new OnClickListener() {
int button01pos = 0;
public void onClick(View v) {
if (button01pos == 0) {
button01.setImageResource(R.drawable.star);
button01pos = 1;
} else if (button01pos == 1) {
button01.setImageResource(R.drawable.startclicked);
button01pos = 0;
}
}
});
return v;
}
}