我的 ListView 有一个自定义适配器,它有多个 TextView。我想为我的 ListView 设置一个 onItemClickListener 并从 TextViews 中提取文本。我尝试使用这个:
String s =(String) ((TextView) mListView.findViewById(R.id.myNr)).getText();
但正如预期的那样,默认情况下它总是返回第一个列表项的值!(我猜是因为它没有从列表中指定项目 ID)
我也试过这个:
String s = (((TextView) mListView.getItemAtPosition(myItemInt)).
findViewById(R.id.myNr)).toString();
没用!有什么建议么?
这是在以下功能下实现的:
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView,
int myItemInt, long mylng) {
// String s statements
}
编辑:
这是完整的代码:
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();
}