2

我正在处理 android 中的列表视图,我在列表视图的每个项目上放置了编辑文本现在我想选择该列表视图的一些项目并只想获取所选项目的数据,我的意思是我已经填写的项目编辑文本。

我正在使用列表适配器将数据获取到列表视图中,如果你明白我的意思,现在给我一些建议。

4

1 回答 1

0

Android:从 ListView 访问子视图

int wantedPosition = 10; // Whatever position you're looking for
int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); // This is the same as child #0
int wantedChild = wantedPosition - firstPosition;
// Say, first visible position is 8, you want position 10, wantedChild will now be 2
// So that means your view is child #2 in the ViewGroup:
if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
  Log.w(TAG, "Unable to get view for desired position, because it's not being displayed on screen.");
  return;
}
// Could also check if wantedPosition is between listView.getFirstVisiblePosition() and listView.getLastVisiblePosition() instead.
View wantedView = listView.getChildAt(wantedChild);

接着:

EditText yourEditText = (EditText)wantedView.findViewById(R.id.yourEditTextId);
于 2013-08-01T21:34:46.790 回答