【问题标题】:how to get data from different items in a listview in android如何从android的listview中的不同项目获取数据
【发布时间】:2013-06-17 05:24:59
【问题描述】:

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

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

【问题讨论】:

  • 您可以为列表视图的每个编辑文本使用焦点更改侦听器,当您将焦点更改为另一个编辑文本时,您可以将值保存在 arraylist 及其位置。如果有帮助,请投票给我;)

标签: android listview


【解决方案1】:

来自Android: Access child views from a 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多