I have certain entries in my list view item.
when i click on Item first like button....only last item like button color value is changing. when i click on Item second like button ....only last item like button color value is changing. But
when i click on first item i got position = 0 and offer_id = O101
when i click on Second item i got position = 1 and offer_id = O103
when i click on third item i got position = 2 and offer_id = O104
every time when i click on any like button of any item of list view ... the like button of last item of list view color gets changed.
I want that whenever i click on any like button of list item, the like button of only that list item should change. how to get this corrected. This is my code....
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.offer_list_item,
parent, false);
holder.tv1 = (TextView) convertView
.findViewById(R.id.offer_name);
holder.tv2 = (TextView) convertView
.findViewById(R.id.expiry_date);
holder.b1 = (Button) convertView.findViewById(R.id.like_button);
holder.b2 = (Button) convertView
.findViewById(R.id.share_button);
holder.tvoid = (TextView) convertView
.findViewById(R.id.offer_id);
holder.tv = (TextView) convertView.findViewById(R.id.like);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final OfferItem it = item.get(position);
holder.tv1.setText(it.getoffer_name());
final String message = holder.tv1.getText().toString();
holder.tv2.setText("Offer ends: " + it.getexpiry_date());
holder.tvoid.setText(it.getoffer_id());
holder.tv.setText("Like");
id_offiers_list.add(it.getoffer_id());
holder.b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String offerid = id_offiers_list.get(position);
System.out.println(offerid);
if (clicked) {
System.out.println(position);
holder.b1
.setBackgroundResource(R.drawable.like_icon_hover);
holder.tv.setTextColor(Color.parseColor("#eaa232"));
clicked = false;
} else {
System.out.println(position);
holder.b1.setBackgroundResource(R.drawable.like_icon);
holder.tv.setTextColor(Color.parseColor("#454545"));
clicked = true;
}
}
});
holder.b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent facebookIntent = new Intent(Intent.ACTION_SEND);
facebookIntent.setType("text/plain");
// facebookIntent.setPackage("com.facebook.katana");
facebookIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(facebookIntent,
"Share..."));
}
});
return convertView;
}