Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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
Java 恢复适配器';当移动到FragmentB并使用back按钮返回时,s SparseBooleanFragmentA数组?_Java_Android Studio_Listview_Fragment - Fatal编程技术网

Java 恢复适配器';当移动到FragmentB并使用back按钮返回时,s SparseBooleanFragmentA数组?

Java 恢复适配器';当移动到FragmentB并使用back按钮返回时,s SparseBooleanFragmentA数组?,java,android-studio,listview,fragment,Java,Android Studio,Listview,Fragment,我有两个碎片。两者都有一个ListView和一个UserAdapter。片段B的列表视图由片段A的选定列表项组成。两个片段中当前选中(选定)的列表项保存在SparseBooleanArray SelectedDS中 我通过Navigation Component在片段之间导航,并传递一个数组,通过读取SparseBooleanArray值得到该数组: FragmentADirections.ActionFragmentAToFragmentB action = FragmentADirectio

我有两个碎片。两者都有一个ListView和一个UserAdapter。
片段B
的列表视图由
片段A
的选定列表项组成。两个片段中当前选中(选定)的列表项保存在
SparseBooleanArray SelectedDS

我通过
Navigation Component
在片段之间导航,并传递一个数组,通过读取
SparseBooleanArray
值得到该数组:

FragmentADirections.ActionFragmentAToFragmentB action = FragmentADirections.actionFragmentAToFragmentB(array);
Navigation.findNavController(view).navigate(action);
列表视图
项有一个附加的选择器,用于其背景绘图。我使用以下代码切换checked状态(它是适配器类中的一个自写方法):


这看起来像C。如果您在问题中添加了语言标记,可能会有所帮助。@robbpriestley谢谢您提供的信息,我已经添加了它。
listView.setOnItemClickListener((new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            adapter.toggleSelection(position);
        }
@Override
public void onViewCreated(@NonNull View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    adapter = new UserAdapter(getContext(), R.layout.list_item, userList);
}