I have a Button which when clicked will execute an addQty method and in this method I need to set the value of a TextView on the same line as the Button was pressed. I have the position integer available to me but I cannot work out how to get the TextView.
I have a custom ArrayAdapter which sets this in the getView method:
ImageButton plus = (ImageButton) v.findViewById(R.id.qtyPlus);
plus.setTag(position);
My layout then does the following:
<ImageButton
android:id="@+id/qtyPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/plus"
android:onClick="addQty" />
My addQty method:
public void addQty(View v) {
int position = Integer.parseInt(v.getTag().toString());
Item tmp = (Item)adapter.getItem(position);
Log.d("MyApp",tmp.getName());
}
This works as I am able to get the item object of the clicked row in the list, but how do I now set a TextView value in that ListView row?
You don’t set a new
TextViewvalue for that list row directly, instead you update theItemelement with the new value and then callnotifyDataSetChanged()(on the adapter object) to notify the adapter that you modified something and that it should update theListView.