Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ArrayAdapter IndexOutOfBoundsException_Android - Fatal编程技术网

Android ArrayAdapter IndexOutOfBoundsException

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);

我正试图通过onclick操作从listview中删除一项。但我得到的是arrayindexoutofbound异常。我从11大小的数组中删除了该项,但它仍在尝试获取11。项目

        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();
}