This code belongs to Fragment wallpaper, over here it doent save its position. if i scroll down and click on that wallpaper it opens and then when i go back recycler view will go to top position
public class wallpaper extends Fragment {
RecyclerView recview;
myadapter adapter;
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_wallpaper, container, false);
recview = (RecyclerView) view.findViewById(R.id.recview);
//3 for a 5 when the user rotates the phone
if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
recview.setLayoutManager(new GridLayoutManager(getActivity(), 2));
} else {
recview.setLayoutManager(new GridLayoutManager(getActivity(), 3));
}
//Calling source and layout from Model.class
FirebaseRecyclerOptions<model> options =
new FirebaseRecyclerOptions.Builder<model>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Wallpapers"), model.class)
.build();
adapter = new myadapter(options);
recview.setAdapter(adapter);
FloatingActionButton fabwallbtn = (FloatingActionButton) view.findViewById(R.id.fabwallpaperbutton);
final DrawerLayout drawer = (DrawerLayout) getActivity().findViewById(R.id.Drawer_Layout);
fabwallbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer(GravityCompat.START);
}
});
return view;
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
}
Recyclerview doesnt save its position.