自定义ArrayAdapter getView提供了错误的位置
因此,我收到错误,因为我的 Custom ArrayAdapter getView 方法提供的位置超出了列表中的项目数。例如,当我有一项时,当我返回此活动后,它会返回位置 1。
编辑:
private class CustomAdapter extends ArrayAdapter<LinearLayout>{
public CustomAdapter(Context context, int resources, List<LinearLayout> objects){
super(context, resources, objects);
}
public View getView(int position, View convertView, ViewGroup parent){
LinearLayout row;
LayoutInflater mInflater = getLayoutInflater();
if (convertView == null){
row = getItem(position);
}
else{
row = (LinearLayout) mInflater.inflate(R.layout.list_row, null);
TextView name = (TextView) row.findViewById(R.id.text1);
name.setText(settingList.get(position).name);
TextView value = (TextView) row.findViewById(R.id.text2);
value.setText(settingList.get(position).value);
}
return row;
}
}
So I'm getting an error because my Custom ArrayAdapter getView method provides a position that is outside of the number of items in my list. For instance, when I have one item it returns a position of 1 after I return to this activity.
EDIT:
private class CustomAdapter extends ArrayAdapter<LinearLayout>{
public CustomAdapter(Context context, int resources, List<LinearLayout> objects){
super(context, resources, objects);
}
public View getView(int position, View convertView, ViewGroup parent){
LinearLayout row;
LayoutInflater mInflater = getLayoutInflater();
if (convertView == null){
row = getItem(position);
}
else{
row = (LinearLayout) mInflater.inflate(R.layout.list_row, null);
TextView name = (TextView) row.findViewById(R.id.text1);
name.setText(settingList.get(position).name);
TextView value = (TextView) row.findViewById(R.id.text2);
value.setText(settingList.get(position).value);
}
return row;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该位置应基于您在重写的 getCount() 方法中返回的任何内容。你为此做什么?
The position should be based off of whatever you return in your overridden
getCount()
method. What are you doing for that?