Update your adapter as follows, this code will update the text
and count
when button is clicked:
public class ProductAdapter extends ArrayAdapter<Product> {
LayoutInflater inflater;
static int resId;
public ProductAdapter(Context context, int resource, int textViewResourceId, List<Product> products) {
super(context, resource, textViewResourceId, products);
this.inflater = LayoutInflater.from(context);
setResId(resource);
}
public View getView(int position, View convertView, ViewGroup parent) {
Product product = getItem(position);
final PlaceItemHelper helper;
if (convertView == null) { // if it's not recycled, initialize some attributes
convertView = inflater.inflate(resid, parent, false);
TextView productName = (TextView) convertView.findViewById(R.id.productNameTextView);
TextView productItem = (Button) convertView.findViewById(R.id.product_button);
TextView productCount = (Button) convertView.findViewById(R.id.product_count);
helper = new PlaceItemHelper(productName, productItem, productCount);
convertView.setTag(helper);
} else {
helper = (PlaceItemHelper) convertView.getTag();
}
helper.getProductName().setText(product.getName());
helper.getProductCount().setText("100");
helper.getProductItem().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.getProductCount().setText("200");
helper.getProductName().setText("Name");
}
});
return convertView;
}
public static int getResId() {
return resId;
}
public static void setResId(int resId) {
ProductAdapter.resId = resId;
}
}
Please go through the above code and notice how I have used the PlaceItemHelper helper
and removed private fields
from the adapter class
.