Android ArrayAdapter IndexOutOfBoundsException
我正试图通过onclick操作从listview中删除一项。但我得到的是arrayindexoutofbound异常。我从11大小的数组中删除了该项,但它仍在尝试获取11。项目Android ArrayAdapter IndexOutOfBoundsException,android,Android,我正试图通过onclick操作从listview中删除一项。但我得到的是arrayindexoutofbound异常。我从11大小的数组中删除了该项,但它仍在尝试获取11。项目 public void onClick(View v) { data.remove(getItemIndexByID(filteredData.get(position).getID())); filteredData.remove(position);
public void onClick(View v) {
data.remove(getItemIndexByID(filteredData.get(position).getID()));
filteredData.remove(position);
notifyDataSetChanged();
flipMenu(lastHolder, 1);
showPopup("Item Deleted");
}
日志:
我注意到ArrayAdapter的getcount方法总是返回相同的值,我像这样重写了getcount()方法,它可以工作
@Override
public int getCount() {
return filteredData.size();
}
position
从何而来?position
第二次似乎是错误的。是否正确更新?位置在这里;@Override public View getView(final int position,View convertView,ViewGroup parent)onclick方法在getView方法中。我正在使用getView的位置值数据是如何声明的?如果您有一个List
子体,它会完全混淆List.remove
方法。在我的例子中,这还不够,getItem也必须被重写,这里的一个例子是:重写并返回filteredData.size(),doThanks的主要内容就是它。吸取的教训是,当我们重写过滤器时,我们就会重写getFilter()和getCount()方法。
@Override
public int getCount() {
return filteredData.size();
}