我有两个RecylerView
,一个在另一个里面。现在,我想在单击某项时更新我的内部recyclerView项。因此,在更新本地数据库后,我将调用notifyDataSetChanged()
,但这不会再次调用我的onBindViewHolder()
。
下面是我的onItemClick()
代码:
public class MyViewHolder extends RecyclerView.ViewHolder {
private ImageView imageView;
private TextView tvTutorialName, text_new;
private ConstraintLayout main_item;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
main_item = itemView.findViewById(R.id.main_item);
tvTutorialName = itemView.findViewById(R.id.tutorial_name);
text_new = itemView.findViewById(R.id.text_new);
imageView = itemView.findViewById(R.id.tutorial_image);
main_item.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
manager.save("tutorialTapGuide", "notFirstTime");
TutorialViewModel tutorialViewModel = new TutorialViewModel(SmartMirror.getInstance());
int pos = (int) view.getTag();
tutorialName = mVideoList.get(pos).serverFolderName;
tutorialId = mVideoList.get(pos).objectId;
// update
tutorialViewModel.updateNewTutorialToOld(tutorialName);
notifyDataSetChanged();
// allCheckingAfterStoragePermissionGranted(view.findViewById(R.id.tutorial_image), pos);
}
});
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int position) {
myViewHolder.main_item.setTag(position);
String tutorialFolder = mVideoList.get(position).serverFolderName;
myViewHolder.tvTutorialName.setText(mVideoList.get(position).displayTutorialName);
myViewHolder.main_item.setTransitionName("trans_image" + position);
TutorialViewModel tutorialViewModel = new TutorialViewModel(SmartMirror.getInstance());
int isNewTutorial = tutorialViewModel.isNewTutorial(tutorialFolder);
if (isNewTutorial == 1)
myViewHolder.text_new.setVisibility(View.VISIBLE);
if (CommonUtilities.haveNetworkConnection(mContext)) {
Glide.with(mContext).load(mVideoList.get(position).imageURL)
.apply(new RequestOptions().placeholder(R.drawable.video_placeholder).error(R.drawable.video_placeholder))
.into(myViewHolder.imageView);
} else {
myViewHolder.imageView.setImageResource(R.drawable.video_placeholder);
}
}
我正在设置父recyclerView适配器的子recyclerView适配器。
holder.mAdapter = new TutorialVideoAdapter(mctx, mFrg, mTracker, videosArrayList, parentView, parent_fragment, catList.get(position), tutorialStepsList, player, holder.recyclerView_tutorial);
holder.recyclerView_tutorial.setLayoutManager(new GridLayoutManager(mctx, 3));
holder.recyclerView_tutorial.setAdapter(holder.mAdapter);
holder.recyclerView_tutorial.setScrollY(00);
我现在不知道为什么notifyDataSetChanged()
不触发onBindViewHolder
。