How to change textView in list item on Button click

后端 未结 2 1525
小鲜肉
小鲜肉 2021-01-25 02:15

I want to change my quantity textview to reflect the quantity of a particular item. But on clicking the add and sub buttons, the setText() function does not seem to work. Here i

2条回答
  •  春和景丽
    2021-01-25 03:00

    You have to just call notifyDataSetChanged(); after add and sub button click code.

    For Add

    add.setOnClickListener(new OnClickListener() {
                @Override 
                public void onClick(View v) {
                    // TODO Auto-generated method stub  
                    quant[position]=quant[position]+1;
                    count1 +=1;
                    //holder.number.setText(Integer.toString(quant[position]));
                    holder.number.setText(count1.toString());
                    Toast.makeText(context, Integer.toString(quant[position]), Toast.LENGTH_SHORT).show();
                    Log.d("Quantity",Integer.toString(quant[position]));
                    positiveNumbers.put(holder.uniqueKey,count); //Key -> String.valueOf(position) and Value -> int count
    
                    notifyDataSetChanged();
                } 
            }); 
    

    For Sub

    sub.setOnClickListener(new OnClickListener() {
                @Override 
                public void onClick(View v) {
                    // TODO Auto-generated method stub 
                    quant[position]--;
                    Toast.makeText(context, Integer.toString(quant[position]), Toast.LENGTH_SHORT).show();
                    holder.number.setText(Integer.toString(quant[position]));
                    positiveNumbers.put(holder.uniqueKey,count);   //Key -> String.valueOf(position) and Value -> int count
    
                   notifyDataSetChanged();
                } 
            });
    

    Hope it's help !!

提交回复
热议问题