I have created an activity that contains a listview with a custom row view.
Row View:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="1dp" >
<TableRow
android:id="@+id/row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/itemID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/itemDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />
<TextView
android:id="@+id/itemRequested"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<EditText
android:id="@+id/itemCompleted"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
</TableRow>
</TableLayout>
I am binding an ArrayList to my list view with a custom adapter class I created. Here is my Item class:
public class Item {
@SerializedName("ItemID")
public int ItemID;
@SerializedName("ItemDescription")
public String ItemDescription;
@SerializedName("ItemModel")
public String ItemModel;
@SerializedName("ItemCartons")
public int ItemCartons;
}
What I am doing is showing my ArrayList in the activity listview with the custom layout which works perfectly. When the user is viewing the listview I want them to be able to enter a value in the itemCompleted EditText control so I can update the item with the completed quantity. When my update event is triggered (button on actionbar) I am iterating through the listview and getting the values out of the custom layout like so:
for (int i = 0; i < mListView.getCount(); i++) {
View v = mListView.getAdapter().getView(i, null, null);
TextView requested = (TextView) v
.findViewById(R.id.itemRequested);
EditText completed = (EditText) v
.findViewById(R.id.itemCompleted);
TextView itemID = (TextView) v.findViewById(R.id.itemID);
int req = Integer.parseInt((String) requested.getText());
int comp = Integer.parseInt(completed.getText().toString());
int id = Integer.parseInt((String) itemID.getText());
if (comp <= req) {
//update item here
} else {
// qty is too much
return;
}
}
My problem is that I am unable to retrieve the value that was entered in the itemCompleted EditText control. It is always pulling the default value and not the value entered by the user. Is there a way I can pull the entered value from the EditText?