espa_network espa_network - 1 year ago 67
Android Question

TextView value changes back to previous value after scroll in base adapter

I've been researching this forever and can't find a solution. Everything about my custom list view seems to perform correctly. When I click on the

, the text changes
correctly. However, when I scroll down and scroll back up, the text value is reverted to the value it had before it was clicked.

I refuse to use
because I am not adding anything or removing anything from the list.

public class CustomFeedListViewAdapter extends BaseAdapter{

CustomFeedListViewAdapter customFeedListViewAdapter;
Date createdAt, currentDate; int num;
static HashMap<String, String> oneData = new HashMap<String, String>();
HashMap<String, String> iFeed = new HashMap<>();

private String likesString;

String upVoteClicked, downVoteClicked;
HashMap<String, String> mFeed = new HashMap<>();
List<ParseObject> mObjects;

private ParseObject parseObFeed;

CustomFeedListViewAdapter(Context context, ArrayList<HashMap<String, String>> data) {

this.mContext = context;
GlobalFeedTab.arrayFeedList = data;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

public int getCount() {
return GlobalFeedTab.arrayFeedList.size();

public Object getItem(int i) {
return GlobalFeedTab.arrayFeedList.get(i);

public long getItemId(int i) {
return i;

public View getView(int i, View view, ViewGroup viewGroup) {

likes = new int[GlobalFeedTab.arrayFeedList.size()];
countryNames = new int[GlobalFeedTab.arrayFeedList.size()];
dateNames = new String[GlobalFeedTab.arrayFeedList.size()];

final 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(;
holder.feedUpVoteButton = (Button) view.findViewById(;

} else {
position = i;
holder = (ViewHolder) view.getTag();

mFeed = GlobalFeedTab.arrayFeedList.get(position);


likesString = mFeed.get("likes");
likes[position] = Integer.valueOf(likesString);


ParseQuery<ParseObject> query2 = new ParseQuery<ParseObject>("FeedItem");

query2.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> objects, ParseException e) {

if (e == null) {

for ( final ParseObject object : objects) {

holder.feedUpVoteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

int pos = (Integer) v.getTag();
parseObFeed = objects.get(pos);
username = parseObFeed.getString("username");
createdAt = parseObFeed.getDate("createdAt");

likes[pos] += 1;
parseObFeed.put("likes", likes[pos]);

parseObFeed.put(ParseUser.getCurrentUser().getUsername() + "upvoteClicked", true);



return view;

private class ViewHolder {

ImageView feedProfilePic;
TextView feedUsername;
TextView feedNumOfLikes;
TextView feedFeedItem;
TextView feedDate;
TextView feedNumofReplies;
Button feedUpVoteButton;
Button feedDownVoteButton;
Button feedCommentButton;
ListView feedListView;



Answer Source

After continuous trial and error. I finally figured out how to change a textview after it scrolls. My problem was I was getting the wrong ParseObject value. My main activity contains a ParseQuery and I was getting the likesfrom a Hashmap(); However, for some reason I couldn't pass the value of likes directly so I passed the ParseObject itself. Therefore, needing no query in my BaseAdapter Class. Then, I implemented these lines of code in GetView(); to answer my original question:

   holder.upvote[position] =  holder.parseObList[position].getBoolean(ParseUser.getCurrentUser().getUsername() + "upvoteClicked");
    holder.downvote[position] =  holder.parseObList[position].getBoolean(ParseUser.getCurrentUser().getUsername() + "downvoteClicked");

    if(holder.upvote[position]  ){

    else if(!holder.upvote[position]){


    else if(!holder.downvote[position]){

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download