相关疑难解决方法(0)

维护方向更改时的项目选择

我正在尝试恢复方向更改的操作模式的状态.但它不能正常工作.按照以下步骤顺序,在#3和#4中,选择被破坏:

  1. 长按项目 - 项目突出显示,上下文操作栏显示标题显示"1选中".看起来不错.
  2. 将手机转为风景 - 没有变化.看起来不错.
  3. 将手机设置为纵向 - 项目未突出显示,上下文操作栏消失
  4. 长按项目 - 项目突出显示,上下文操作栏显示标题显示"0已选中"

myListView.getCheckedItemCount()onSaveInstanceState()#3上返回0.这就是问题开始的地方.

我的片段(使用支持库)我做错了什么?

@Override
public void onSaveInstanceState(Bundle outState) {
    //check if any items are selected
    if (myListView.getCheckedItemCount() > 0) {
        //get the list of selected items and convert it to an int Array
        //because SparseBooleanArray cannot be stored in a bundle
        SparseBooleanArray selectedItems = myListView.getCheckedItemPositions();
        int[] selectedItems_intArray = new int[myListView.getCheckedItemCount()];
        for (int i = 0; i < selectedItems.size(); i++) {
            if (selectedItems.valueAt(i) == false)
                continue; …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-support-library

2
推荐指数
1
解决办法
1966
查看次数