-1

I want to update in and ArrayAdapter a TextView when user will click + or - button. I cannot figure out how can I change data of individual in ArrayApapter.
Here is a image for better explanation what I want to do :

How can I change data of 0 after clicking on + or - button

public View getView(int position, View countView, ViewGroup parent) {

    View listView = countView;
    if (listView == null) {
        listView = LayoutInflater.from(getContext()).inflate(R.layout.listview, parent, false);
    }


    word currentWord = getItem(position);
    TextView foodName = (TextView) listView.findViewById(R.id.food);
    Button minus = (Button) listView.findViewById(R.id.minus);
    Button add = (Button) listView.findViewById(R.id.add);
    TextView total = (TextView) listView.findViewById(R.id.total);


    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }
    });
    minus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }
    });
    return listView;
}
Pengyy
  • 37,383
  • 15
  • 83
  • 73
Nayan
  • 5
  • 3

2 Answers2

0

Inside onClickListener, Increase or decrease the quantity and call onDataSetChanged().

Nirup Iyer
  • 1,215
  • 2
  • 14
  • 20
0

Whenever you are making a change through onclicklistener then just only change your data. like if your are using ArrayList> then just change the any value whatever you want like if your press 4th element with add+ then get the 4th item from the list and set it to +1. and then refresh your adapter with notifydatasetChanged().

In the above code you are only showing the UI part in the list whenever you will use data with you can do it then very easily.

Android Geek
  • 8,956
  • 2
  • 21
  • 35