In my GetView()
method of my BaseAdapter
class... I have a view holder. When I click the holder.feedUpVotebutton
The feed.numOFLikes
Textview gets incremented. The problem is when I scroll down and scroll back up, the value is back to its original value. I refuse to call notifydatasetChanged();
because I am not adding anything or removing anything from the list.
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
likes = new int[GlobalFeedTab.arrayFeedList.size()];
ViewHolder holder;
if (view == null) {
position = i;
view = inflater.inflate(R.layout.feed_list_row, viewGroup, false);
holder = new ViewHolder();
holder.feedNumOfLikes = (TextView) view.findViewById(R.id.feedNumofLikes);
holder.feedUpVoteButton = (Button) view.findViewById(R.id.feedUpVoteButton);
view.setTag(holder);
}
else if(view != null){
position = i;
holder = (ViewHolder) view.getTag();
}
HashMap<String, String> mFeed = new HashMap<>(); //Hashmap of data that I get from the MainActivity
mFeed = GlobalFeedTab.arrayFeedList.get(position);
holder.feedNumOfLikes.setText(mFeed.get("likes"));
holder.feedUpVoteButton.setTag(position);
holder.feedUpVoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = (Integer) v.getTag();
ParseObject parseObFeed = objects.get(pos);
likes[pos] += 1;
parseObFeed.put("likes", likes[pos]);
holder.feedNumOfLikes.setText(String.valueOf(parseObFeed.getInt("likes")
)); //This is where I set the Text
parseObFeed.saveInBackground();
}
});
}
class ViewHolder {
TextView feedNumOfLikes;
Button feedUpVoteButton;
}