How to Increase or decrease value of edittext in listview's each row?

后端 未结 3 1033
暖寄归人
暖寄归人 2021-01-22 10:57

I create one Listview, in my Listview I have two Buttons and one Edittext. In my Edittext I want to increase the

3条回答
  •  不要未来只要你来
    2021-01-22 11:24

    You cant access use local variables in this case, By the time the onClickListener is called the variables would have gone out of scope.

    So instead you can set the ViewHolder as a tag for the button too, then you can access that in your onClick.

    holder.btnEdit.setTag(holder);
    holder.btnEdit.setOnClickListener(new OnClickListener() {
    
       @Override
       public void onClick(View v) {
         ViewHolder tagHolder = (ViewHolder) v.getTag();
    
        // TODO Auto-generated method stub
        Log.i("Edit Button Clicked", "**********");
       /* Toast.makeText(context, "Edit button Clicked",
          Toast.LENGTH_LONG).show();*/
    
        int mValue = Integer.parseInt(tagHolder.textAddress.getText().toString());
        mValue--;
        if(mValue < 0)
        {
            System.out.println("not valid");
        }
        else
        {
            tagHolder.textAddress.setText( ""+mValue );
        }
       }
      });
    

    I hope it helps!

提交回复
热议问题