I have a Listview that originally listed items from a menu item with one single TextView. The code I used to retrieve the item selected is
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id)
{
TextView textView = (TextView) itemClicked;
String strText = textView.getText().toString();
});
I’ve now added another TextView so that I have two values for each item one under the other and my menu_item.xml looks like this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10sp">
<TextView
android:id="@+id/rowid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/exhibitor_header" />
<TextView
android:id="@+id/rowidtwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/listview_background"
android:layout_below="@+id/rowid"/>
</RelativeLayout>
How can I retrieve the value for rowid when the item is selected?
Then instead of casting the whole view, find inside that view the correct
TextViewobject. You can reference it by using thefindViewByIdmethod and theTextView‘s id: