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 tutorials, but still it's not working in my Listview
can anyone help me with that?
I follow this tutorial: http://www.androidhub4you.com/2013/02/muftitouch-listview-multi-click.html
It shows: Cannot refer to the non-final local variable holder defined in an enclosing scope
Code:
public class UserCustomAdapter extends ArrayAdapter<User> {
Context context;
int layoutResourceId;
ArrayList<User> data = new ArrayList<User>();
public UserCustomAdapter(Context context, int layoutResourceId,
ArrayList<User> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
UserHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.textName = (TextView) row.findViewById(R.id.textView1);
holder.textAddress = (EditText) row.findViewById(R.id.textView2);
holder.textLocation = (TextView) row.findViewById(R.id.textView3);
holder.btnEdit = (Button) row.findViewById(R.id.button1);
holder.btnDelete = (Button) row.findViewById(R.id.button2);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
User user = data.get(position);
holder.textName.setText(user.getName());
//holder.textAddress.setText(user.getAddress());
holder.textLocation.setText(user.getLocation());
holder.btnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("Edit Button Clicked", "**********");
/* Toast.makeText(context, "Edit button Clicked",
Toast.LENGTH_LONG).show();*/
int mValue = Integer.parseInt(holder.textAddress.getText().toString());
mValue--;
if(mValue < 0)
{
System.out.println("not valid");
}
else
{
holder.textAddress.setText( ""+mValue );
}
}
});
holder.btnDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("Delete Button Clicked", "**********");
/* Toast.makeText(context, "Delete button Clicked",
Toast.LENGTH_LONG).show();*/
}
});
return row;
}
static class UserHolder {
TextView textName;
EditText textAddress;
TextView textLocation;
Button btnEdit;
Button btnDelete;
}
}
final UserHolder holder
– Meliamelic