-1

我有一个活动作为singleTop

这是 oncreate() 的一部分

    ListView mainListView = (ListView) findViewById(R.id.order_item_list);
     mainListView.clearChoices();
     mainListView.requestLayout();

     listAdapter = new OrderItemAdapter(this,
            R.layout.list_item_order_item, OrderActivity.Order.OrderItems);

    mainListView.setAdapter(listAdapter);

    SparseBooleanArray checkedItems= mainListView.getCheckedItemPositions();
    Log.println(2, "s", Integer.toString(checkedItems.size() ));
}

然后使用调试器checkedItems 为0。但是当我从操作中获取它时单击它,checkedItems 具有以前的值。再次使用调试器的引用似乎在同一个对象上。我能对这件事做些什么吗?因为它会导致很多问题。

@Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        switch (menuItem.getItemId()) {
        case android.R.id.home:

            //finish();
            // NavUtils.navigateUpFromSameTask(this);
            confirmExit();
            return true;

        case R.id.delete_button:
            ListView mainListView = (ListView) findViewById(R.id.order_item_list);

            SparseBooleanArray checkedItems= mainListView.getCheckedItemPositions();
            boolean hasOld=false;
            break;
        }
        return true;
    }
4

1 回答 1

0

问题似乎来自这里。

https://github.com/android/platform_frameworks_base/blob/android-cts-2.3_r12/core/java/android/widget/ListView.java

   @Override
        public Parcelable onSaveInstanceState() {
            Parcelable superState = super.onSaveInstanceState();
            return new SavedState(superState, mCheckStates, mCheckedIdStates);
        }

        @Override
        public void onRestoreInstanceState(Parcelable state) {
            SavedState ss = (SavedState) state;

            super.onRestoreInstanceState(ss.getSuperState());

            if (ss.checkState != null) {
               mCheckStates = ss.checkState;
            }

            if (ss.checkIdState != null) {
                mCheckedIdStates = ss.checkIdState;
            }
        }
于 2013-01-15T16:51:18.707 回答