4

onclickアクションでリストビューからアイテムを削除しようとしています。しかし、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"); 


        }

ログ:

    11-26 17:16:32.159: E/AndroidRuntime(26991): FATAL EXCEPTION: main
11-26 17:16:32.159: E/AndroidRuntime(26991): java.lang.IndexOutOfBoundsException: Invalid index 10, size is 10
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.util.ArrayList.get(ArrayList.java:304)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.innovationbox.passlocker.adapters.ListViewAdapter.getView(ListViewAdapter.java:100)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView.obtainView(AbsListView.java:2143)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.makeAndAddView(ListView.java:1831)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.fillDown(ListView.java:674)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.fillGap(ListView.java:638)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4930)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4087)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer.doFrame(Choreographer.java:531)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Handler.handleCallback(Handler.java:725)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Looper.loop(Looper.java:137)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.app.ActivityThread.main(ActivityThread.java:5039)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.lang.reflect.Method.invokeNative(Native Method)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.lang.reflect.Method.invoke(Method.java:511)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

16

ArrayAdapterのgetcountメソッドが常に同じ値を返すことに気付きました。このようにgetCount()メソッドをオーバーライドすると、機能します。

@Override
public int getCount() {
    return filteredData.size();
}
于 2012-11-26T17:12:42.627 に答える