I have a fragment holding a recyclerview, and when I tap on an item I want the textviews within it to fade out for a scene transition into an Activity. When I hit the back button to go back to the fragment, the text in the recyclerview item should fade back in. The problem is that this only works for the first item in the recyclerview. For any other item, the text fades out but stays invisible when I move back to the fragment.
toggleVisibility method call in the Adapter's onBindViewHolder:
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String imageTransitionName = context.getString(R.string.timeline_item_transition_image);
Pair imagePair = new Pair<>(view.findViewById(R.id.timeline_image_framelayout), imageTransitionName);
ActivityOptionsCompat optionsCompat =
ActivityOptionsCompat.makeSceneTransitionAnimation(mUpcomingEventsFragment.getActivity(),
imagePair);
toggleVisibility(holder.itemView, false);
view.getContext().startActivity(EventDetailActivity.newIntent(context,
(Event) mTimelineItemList.get(holder.getAdapterPosition())), optionsCompat.toBundle());
}
});
And the method with the TransitionManager's fade:
public void toggleVisibility(View view, boolean visible) {
TransitionManager.beginDelayedTransition((ViewGroup) view, new Fade());
TextView timeText = (TextView) view.findViewById(R.id.event_time);
TextView titleText = (TextView) view.findViewById(R.id.event_title);
timeText.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
titleText.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
}
I am calling the toggleVisibility
method when the fragment resumes, mUpcomingEventsAdapter.toggleVisibility(mRecyclerView, true);
but my problem is that I'm just not sure how to set the visibility correctly on the selected item from the recyclerview when I go back to the fragment.