Android - Unable to increment or decrement value from list item

前端 未结 3 1941
醉话见心
醉话见心 2020-12-03 20:37

Hi everyone i am using custom listview for getting data from server and show in listview.. I am able to get data and show it in listview but i dont know to implement the cli

3条回答
  •  无人及你
    2020-12-03 21:10

    Currently you have 1 variable per activity to store the quantity. If you want to store it per item, you should add: int qty; to be a member in FeedItem class.

    Remove:

    convertView.setTag(Integer.valueOf(id));
    

    and similar to plus, you'll need to add:

    minus.setTag(item.getId());
    

    Then instead of qty++; or basically in every place in the onClick instead of qty you'll need to use item.qty:

    Integer id = view.getTag();
    FeedItem item = filteredfeedItems.get(id);
    item.qty++;
    location.setText(String.valueOf(item.qty));
    

    Update:

    I think you're mixing FeedItem.id with position. If you're not changing the order / amount of items in the list then you could ALWAYS use position. Instead of:

    minus.setTag(item.getId());
    

    try:

    minus.setTag(position);
    

    and the same for plus

提交回复
热议问题