Индекс массива Android ListView за пределами фильтра

Я думаю, что это вопрос для экспертов.

Мне звонятgetView() с участиемpositon за границами изПосмотреть список список данных.
Это происходит, когда я использую фильтр адаптера. ФильтрpublishResults() Метод заполняет данные отфильтрованным списком, который меньше исходного списка.
Кажется, ошибка возникает, когда новый отфильтрованный списоккороче предыдущего отфильтрованный список. Я изменил кодgetView() вернуть манекенconvertView когда выходит за пределы, просто чтобы посмотреть, сколько таких звонков.

Это соответствующий код иlog сообщения, которые я зарегистрировал:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // No logs here to keep ListView performance good
        Log.d(TAG, "+ getView( position=" + position + ")");
        ViewHolder holder;

        if( position >= mData.size() ) {
            // This code allows to see how many bad calls I get
            Log.w(TAG, "position out of bounds!");
            convertView = mInflater.inflate(mLayout, parent, false);
            return convertView;
        }

        . . . // Normal getView code

        return convertView;
    }

В фильтре (код скопирован как есть изArrayAdapter исходный код)

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            Log.pe(TAG, "+ publishResults(constraint:" + constraint + ", results.count:" + results.count + ")");
            //noinspection unchecked
            mData = (ArrayList<String>) results.values;
            if (results.count > 0) {
                notifyDataSetChanged();
            } else {
                notifyDataSetInvalidated();
            }
            Log.px(TAG, "- publishResults()");
        }

Файл журнала показывает, что после фильтра с 7 результатами появляется файл с 3 результатами, ноgetView продолжает получать звонки на 7 пунктов (я отмечен*** звонки вне границ):

02-26 05:31:55.986: D/ViewerActivity(22857): + onQueryTextChange(newText:log)
02-26 05:31:55.986: D/ViewerActivity(22857): - onQueryTextChange()
02-26 05:31:56.029: D/LogScreenAdapter(22857): + performFiltering(prefix:log)
02-26 05:31:56.113: D/dalvikvm(22857): GC_CONCURRENT freed 378K, 5% free 13577K/14215K, paused 0ms+1ms
02-26 05:31:56.153: D/LogScreenAdapter(22857): - performFiltering()
02-26 05:31:56.153: D/LogScreenAdapter(22857): + publishResults(constraint:log, results.count:7)
02-26 05:31:56.167: D/LogScreenAdapter(22857): - publishResults()
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=1)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=2)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=3)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=4)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=5)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=6)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=1)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=2)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=3)
02-26 05:31:56.167: D/LogScreenAdapter(22857): + getView( position=4)
02-26 05:31:56.493: D/LogScreenAdapter(22857): + getView( position=5)
02-26 05:31:56.503: D/LogScreenAdapter(22857): + getView( position=6)
02-26 05:32:23.793: D/ViewerActivity(22857): + onQueryTextChange(newText:logs)
02-26 05:32:23.793: D/ViewerActivity(22857): - onQueryTextChange()
02-26 05:32:23.813: D/LogScreenAdapter(22857): + performFiltering(prefix:logs)
02-26 05:32:23.854: D/dalvikvm(22857): GC_CONCURRENT freed 383K, 5% free 13577K/14215K, paused 0ms+0ms
02-26 05:32:23.924: D/dalvikvm(22857): GC_CONCURRENT freed 388K, 5% free 13573K/14215K, paused 0ms+1ms
02-26 05:32:23.974: D/LogScreenAdapter(22857): - performFiltering()
02-26 05:32:23.983: D/LogScreenAdapter(22857): + publishResults(constraint:logs, results.count:3)
02-26 05:32:23.983: D/LogScreenAdapter(22857): - publishResults()
02-26 05:32:23.983: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:32:24.074: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:32:24.093: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:32:24.113: D/LogScreenAdapter(22857): + getView( position=1)
02-26 05:32:24.155: D/LogScreenAdapter(22857): + getView( position=2)
02-26 05:32:24.164: D/LogScreenAdapter(22857): + getView( position=3)
*** 02-26 05:32:24.193: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.233: D/LogScreenAdapter(22857): + getView( position=4)
*** 02-26 05:32:24.263: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.284: D/LogScreenAdapter(22857): + getView( position=5)
*** 02-26 05:32:24.313: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.333: D/LogScreenAdapter(22857): + getView( position=6)
*** 02-26 05:32:24.343: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.353: D/LogScreenAdapter(22857): + getView( position=0)
02-26 05:32:24.373: D/LogScreenAdapter(22857): + getView( position=1)
02-26 05:32:24.383: D/LogScreenAdapter(22857): + getView( position=2)
02-26 05:32:24.403: D/LogScreenAdapter(22857): + getView( position=3)
*** 02-26 05:32:24.413: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.433: D/LogScreenAdapter(22857): + getView( position=4)
*** 02-26 05:32:24.443: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.463: D/LogScreenAdapter(22857): + getView( position=5)
*** 02-26 05:32:24.475: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:32:24.483: D/LogScreenAdapter(22857): + getView( position=6)
*** 02-26 05:32:24.503: W/LogScreenAdapter(22857): position out of bounds!
02-26 05:38:26.769: D/dalvikvm(22857): GC_CONCURRENT freed 316K, 5% free 13640K/14215K, paused 0ms+1ms

То, что вы видите здесь,publishResults() метод изменил mData из списка из 7 элементов в более короткий список из 3 элементов, см. код выше, ноAdapter продолжает получатьgetView() призывает список из 7 пунктов, даже если его больше нет.
Обратите внимание, чтоnotifyDataSetChanged() был вызван с новым назначением данных, поэтомуListView должен знать о новом списке.

Ответы на вопрос(3)

Ваш ответ на вопрос