Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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
Android 从父recyclerView更新子recyclerView项按钮单击_Android_Android Recyclerview - Fatal编程技术网

Android 从父recyclerView更新子recyclerView项按钮单击

Android 从父recyclerView更新子recyclerView项按钮单击,android,android-recyclerview,Android,Android Recyclerview,我有一个parent recyclerView,父项的每个项都有一个子recyclerView。我在父recyclerView上有一个切换按钮,当该按钮被选中时,我必须更新子recyclerView列表。 我尝试了所有可能的方法来更新子列表,但没有成功。下面是我试图更新列表的父适配器的代码: holder.toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

我有一个parent recyclerView,父项的每个项都有一个子recyclerView。我在父recyclerView上有一个切换按钮,当该按钮被选中时,我必须更新子recyclerView列表。 我尝试了所有可能的方法来更新子列表,但没有成功。下面是我试图更新列表的父适配器的代码:

 holder.toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        videosArrayList.clear();
                        allVideoExceptPersonalizedList.clear();
                        allVideoArrayList.clear();
                      setDataForCategory(1,holder,position);
                        holder.mAdapter.UpdateList(videosArrayList);

                    } else {
                        videosArrayList.clear();
                        allVideoExceptPersonalizedList.clear();
                        allVideoArrayList.clear();
                        setDataForCategory(2,holder,position);
                        holder.mAdapter.notifyDataSetChanged();
                        holder.mAllVideoAdapter.notifyDataSetChanged();
                    }
                }
            });
public void UpdateList(List<VideoDetailModel> videosArrayList){
        mVideoList.clear();
        mVideoList.addAll(videosArrayList);
        notifyDataSetChanged(); 
}
在上面的代码中,videoArrayList是我的子列表项,setDataForCategory给了我一个更新的列表

我还尝试再次绑定适配器,但这会使我的childRecyclerView为空,因为它正在清除列表,但没有添加新数据

 holder.mAdapter = new TutorialVideoAdapter(mctx, mFrg, mTracker, videosArrayList,
                                parentView, parent_fragment, catList.get(position),parentCategoryId,
                                holder.recyclerView_tutorial_personalized, new ITutorialImageClick() {
                            @Override
                            public void imageOnClick(View v, int position) {
                                int newTutorialCount = tutorialViewModel.getNewTutorialCount(categoryName, myParams,priority);

                                holder.img_category.setBadgeValue(newTutorialCount);
                            }
                        });
                        holder.recyclerView_tutorial_personalized.setAdapter(holder.mAdapter);
                        holder.recyclerView_tutorial_personalized.invalidate();
下面是我正在更新列表的子适配器的代码:

 holder.toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        videosArrayList.clear();
                        allVideoExceptPersonalizedList.clear();
                        allVideoArrayList.clear();
                      setDataForCategory(1,holder,position);
                        holder.mAdapter.UpdateList(videosArrayList);

                    } else {
                        videosArrayList.clear();
                        allVideoExceptPersonalizedList.clear();
                        allVideoArrayList.clear();
                        setDataForCategory(2,holder,position);
                        holder.mAdapter.notifyDataSetChanged();
                        holder.mAllVideoAdapter.notifyDataSetChanged();
                    }
                }
            });
public void UpdateList(List<VideoDetailModel> videosArrayList){
        mVideoList.clear();
        mVideoList.addAll(videosArrayList);
        notifyDataSetChanged(); 
}
public void UpdateList(列表videosArrayList){
mvideolost.clear();
mvideolost.addAll(videosArrayList);
notifyDataSetChanged();
}
我还尝试重置适配器并调用childRecyclerView.invalidate(),但这对我也没有帮助


我到底做错了什么?

mVideoList.clear()之后您的列表您需要再次绑定适配器它不仅适用于
notifyDataSetChanged()。在清除数组后尝试重新绑定适配器。让我再次编辑我的问题,因为我也尝试过,但这会使我的孩子recyclerView为空。您是否尝试此
rv.setAdapter(mVideoList)吗?我尝试了相同的方法,但只清除了列表,但未设置新列表。好的,请尝试清除列表,分配
adapter=null
,然后绑定
adapter