【发布时间】:2015-05-01 08:38:45
【问题描述】:
我正在尝试从 AutoComplete 中查找作为 ArrayList 的类结构位置,例如我有这样的类结构:
public class Clients {
@DatabaseField(generatedId = true)
public int id;
@DatabaseField
public int client_code;
public int getClient_code() {
return client_code;
}
}
我将此类中的ArrayList 定义为:
private ArrayList<Clients> customersList = new ArrayList<Clients>();
现在我在这个 arrayList 中有一些数据,我想获得选定的位置以查找选择了哪个 client_code。
at_sender_package.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
int selectedposition=position;
Log.e("SELECTED ITEM: ", customersList.get(selectedposition).getClient_code()+"");
}
});
很遗憾,我收到了这个错误:
java.lang.IndexOutOfBoundsException: 无效索引 0,大小为 0 在 java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 在 java.util.ArrayList.get(ArrayList.java:304)
我的数组列表不为空,我有 3 个项目,我没有任何问题来获取选定的文本,我只想获取选定的位置而不是选定的文本
例如:
Log.e("POS: ", parent.getItemAtPosition(position) + "");
结果是:POS: Item 1)
【问题讨论】:
-
只对。列表中什么都没有,那么它将如何显示??
-
@Shadow 帖子已更新,请检查先生,
-
你在哪里插入数据?
-
@Shadow in bakcground and
customersList.size();is 3 -
尝试在 setOnItemClickListener 中记录大小。它返回什么?