How To Increase Or Decrease Value Of Edittext In Listview's Each Row?
I create one Listview, in my Listview I have two Buttons and one Edittext. In my Edittext I want to increase the value of Edittext as per Button's click. I followed so many tutoria
Solution 1:
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(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
ViewHoldertagHolder= (ViewHolder) v.getTag();
// TODO Auto-generated method stub
Log.i("Edit Button Clicked", "**********");
/* Toast.makeText(context, "Edit button Clicked",
Toast.LENGTH_LONG).show();*/intmValue= Integer.parseInt(tagHolder.textAddress.getText().toString());
mValue--;
if(mValue < 0)
{
System.out.println("not valid");
}
else
{
tagHolder.textAddress.setText( ""+mValue );
}
}
});
I hope it helps!
Solution 2:
Edit
Try declaring holder like this, and dont try to redeclare it later in the code.
final UserHolder holder = new UserHolder();
Final variables cant be reassigned
Solution 3:
Use final UserHolder holder;
instead of UserHolder holder = new UserHolder()
.
Post a Comment for "How To Increase Or Decrease Value Of Edittext In Listview's Each Row?"