diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java index 6cf748deb..30dcd0185 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java @@ -295,15 +295,19 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, @NonNull @Override public SimpleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ - FrameLayout view=tabViews[viewType]; - ((ViewGroup)view.getParent()).removeView(view); - view.setVisibility(View.VISIBLE); + FrameLayout view=new FrameLayout(parent.getContext()); view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return new SimpleViewHolder(view); } @Override - public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){} + public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){ + FrameLayout view=tabViews[position]; + if(view.getParent() instanceof ViewGroup parent) + parent.removeView(view); + view.setVisibility(View.VISIBLE); + ((FrameLayout)holder.itemView).addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + } @Override public int getItemCount(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java index 0b067ca37..3fd882faf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java @@ -153,18 +153,21 @@ public class SettingsServerFragment extends AppKitFragment{ @NonNull @Override public SimpleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ - FrameLayout view=tabViews[viewType]; - ((ViewGroup)view.getParent()).removeView(view); - view.setVisibility(View.VISIBLE); + FrameLayout view=new FrameLayout(parent.getContext()); view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return new SimpleViewHolder(view); } @Override public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){ + FrameLayout view=tabViews[position]; + if(view.getParent() instanceof ViewGroup parent) + parent.removeView(view); + view.setVisibility(View.VISIBLE); + ((FrameLayout)holder.itemView).addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); Fragment fragment=getFragmentForPage(position); if(!fragment.isAdded()){ - getChildFragmentManager().beginTransaction().add(holder.itemView.getId(), fragment).commit(); + getChildFragmentManager().beginTransaction().add(view.getId(), fragment).commit(); holder.itemView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ @Override public boolean onPreDraw(){