I have a custom adapter for my ListView which has multiple TextViews. I want to set an onItemClickListener to my ListView and extract text out of the TextViews. I tried using this:
String s =(String) ((TextView) mListView.findViewById(R.id.myNr)).getText();
but as expected by default it always returns the values from the first list item! (I guess because it doesn’t specify the item id from the list)
I also tried this:
String s = (((TextView) mListView.getItemAtPosition(myItemInt)).
findViewById(R.id.myNr)).toString();
didn’t work! Any suggestions?
This is implemented under the following function:
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView,
int myItemInt, long mylng) {
// String s statements
}
EDIT:
Here’s the full code:
mListView_myentries.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView,
int myItemInt, long mylng) {
String workRequestSelected = (String) ((TextView) mListView_myentries.findViewById(R.id.work_request)).getText();
String activitySelected = (String) ((TextView) mListView_myentries.findViewById(R.id.activity)).getText();
String statusSelected = (String) ((TextView) mListView_myentries.findViewById(R.id.status)).getText();
String workRequestDescSelected = (String) ((TextView) mListView_myentries.findViewById(R.id.desc)).getText();
String actualHoursString = (String) ((TextView) mListView_myentries.findViewById(R.id.actual_hours)).getText();
}
Try the below code