gpt4 book ai didi

android - 在自定义适配器上设置 getItem

转载 作者:行者123 更新时间:2023-11-29 17:57:02 26 4
gpt4 key购买 nike

因为我正在为我的应用程序使用自定义 listView 适配器,所以一些默认方法被覆盖了。当我调用适配器的 getItem(position) 方法时出现问题。由于此方法被重写,我试图找出所选项的结果返回为 null。

自定义适配器重写方法如下:

        @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

获取选中项的调用:

public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// retrieve selected items and print them out
ArrayListAdapter adapter = (ArrayListAdapter) Allprojects.this.getListAdapter();
SparseBooleanArray selected = adapter.getSelectedIds();
StringBuilder message = new StringBuilder();
for (int i = 0; i < selected.size(); i++){
if (selected.valueAt(i)) {
String selectedItem = (String) adapter.getItem(selected.keyAt(i));
message.append(selectedItem + "\n");
}
}
Toast.makeText(Allprojects.this, message.toString(), Toast.LENGTH_LONG).show();

// close action mode
mode.finish();
return false;
}

我现在如何重写 getItem(position) 方法,以便获得所选项目。请帮忙。

最佳答案

由于您使用的是 BaseAdapter,因此您必须在其中包含项目的列表(或其他一些集合),对吗?只需使用

return list.get(position);

关于android - 在自定义适配器上设置 getItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com