你的 onItemClick 回调会像这样
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
在这里,您有View view,您只需使用您的布局投射此视图并获取您的 TextView 。这是一个例子:
if (view != null) {
TextView txtView = view.findViewById(R.id.mytextview);
String value=txtView.getText().toString();
}
编辑:
public View getViewByPosition(int pos, ListView listView) {
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
if (pos < firstListItemPosition || pos > lastListItemPosition ) {
return listView.getAdapter().getView(pos, null, listView);
} else {
final int childIndex = pos - firstListItemPosition;
return listView.getChildAt(childIndex);
}
}
只需使用这种方式在您的按钮 onClick() 方法上调用此方法
getViewByPosition(2,YOUR_LIST_VIEW);
此方法将返回您的View 对象的ListView 特定位置。现在您可以使用以前的方式进行投射。
希望对你有帮助:)