I have a custom List View Adapter. When I click a button in a row, I want to change the text in that same row. However, I am getting an error. When I click on the button in row 0, it changes the text in row 1 or 2 instead (random). Also, do I need to usesetTag();
and getTag();
How can I get the button in row 0 to change the text in row 0 when it is clicked.
Custom List Row Code
public CustomFeedListViewAdapter(Context context, ArrayList<HashMap<String, String>> data) {
mContext = context;
feed = data;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
position = i;
View mView = view;
if (view == null) {
mView = inflater.inflate(R.layout.feed_list_row, viewGroup, false);
feedNumOfLikes = (TextView) mView.findViewById(R.id.feedNumofLikes);
feedUpVoteButton = (Button) mView.findViewById(R.id.feedUpVoteButton);
feedDownVoteButton = (Button) mView.findViewById(R.id.feedDownVoteButton);
HashMap<String, String> mFeed = new HashMap<>();
mFeed = feed.get(i);
// feedUpVoteButton.setTag(i);
// feedNumOfLikes.setTag(i);
feedUpVoteButton.setOnClickListener(this);
}
return mView;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.feedUpVoteButton:
//v.getTag();
likes +=1;
Log.i("yo", String.valueOf(position));
feedNumOfLikes.setText(String.valueOf(likes));
break;
case R.id.feedDownVoteButton:
// Do stuff when imageView1 is clicked...
default:
break;
}
}
}