I have a landscape configuration for one of my app's activities. This activity contains a fragment and this fragment contains one textview and one recyclerview. Everytime when i switch in between portrait and landscape modes, the recyclerview leaves the view of itself like however it was before i turned the device. It might be a little difficult to understand what i try to ask here, so i recorded a gif for that.

<https://giphy.com/gifs/3Wv7NAtT8ezP1SQhDu>

This is my activity

```
public class RecipeStepsActivity extends AppCompatActivity {

static Recipe recipe;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipe_steps);

    if (StepDetailActivity.SDA_TAG.equals(StepDetailActivity.NEGATIVE))
        recipe = getIntent().getParcelableExtra("recipe");
    Bundle b = new Bundle();
    b.putParcelable("recipe", recipe);

    ActionBar ab = getSupportActionBar();
    if (ab != null)
        ab.setTitle(recipe.getName());

    RecipeStepsFragment recipeStepsFragment = new RecipeStepsFragment();
    recipeStepsFragment.setArguments(b);
    FragmentManager fm = getSupportFragmentManager();
    fm.beginTransaction().add(R.id.frame_layout_steps, recipeStepsFragment).commit();
}

```

}

This is my fragment

```
public class RecipeStepsFragment extends Fragment {

@BindView(R.id.recipe_steps_rv)
RecyclerView recyclerView;
@BindView(R.id.ingredients_tv)
TextView tv_ingredients;
List<Step> steps;
public RecipeStepsFragment(){}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_recipe_steps, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ButterKnife.bind(this, view);
    List<Ingredients> ingredients;
    Recipe recipe = getArguments().getParcelable("recipe");
    steps = recipe.getSteps();
    initRecyclerView();

    ingredients = recipe.getIngredients();
    String ingredientsAppended = "INGREDIENTS" + "\n\n";
    if (ingredients == null){
        ingredientsAppended = "Not Available";
    } else {
        for (int a = 0 ; a < ingredients.size() ; a++) {
            Ingredients i = ingredients.get(a);
            ingredientsAppended += String.valueOf(i.getQuantity()) + " " +
                    i.getMeasure() + " " +
                    i.getIngredient();
            if (a+1 != ingredients.size()){
                ingredientsAppended += '\n';
            }
        }
    }
    tv_ingredients.setText(ingredientsAppended);
    if(savedInstanceState != null){
        recyclerView.scrollToPosition(savedInstanceState.getInt("position"));
    }
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    outState.putInt("position", recyclerView.getVerticalScrollbarPosition());
    super.onSaveInstanceState(outState);
}

private void initRecyclerView(){
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
    RecipeStepsRecyclerAdapter recipeStepsRecyclerAdapter =
            new RecipeStepsRecyclerAdapter(steps, new RecipeStepsRecyclerAdapter.ClickListener() {
                @Override
                public void onItemClick(int clickedItemPosition) {
                    Intent intentToStepDetail = new Intent(getActivity(), StepDetailActivity.class);
                    Step step = steps.get(clickedItemPosition);
                    intentToStepDetail.putExtra("step", step);
                    startActivity(intentToStepDetail);
                }
            }, getContext());
    recyclerView.setAdapter(recipeStepsRecyclerAdapter);
    recipeStepsRecyclerAdapter.notifyDataSetChanged();
}

```

}

This is my adapter

```
public class RecipeStepsRecyclerAdapter extends RecyclerView.Adapter<RecipeStepsRecyclerAdapter.ViewHolder> {

private List<Step> stepList;
private LayoutInflater mInflater;
final private ClickListener clickListener;

public RecipeStepsRecyclerAdapter(List<Step> stepList, ClickListener clickListener, Context context){
    this.stepList = stepList;
    this.clickListener = clickListener;
    mInflater = LayoutInflater.from(context);
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = mInflater.inflate(R.layout.recipe_steps_recyclerview_adapter, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    Step step = stepList.get(position);
    String stepContent = step.getShortDescription();
    holder.listingNumber.setText(String.valueOf(position+1));
    holder.stepContent.setText(stepContent);
}

@Override
public int getItemCount() {
    return stepList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

    TextView listingNumber;
    TextView stepContent;

    private ViewHolder(View itemView) {
        super(itemView);
        listingNumber = itemView.findViewById(R.id.list_number_tv);
        stepContent = itemView.findViewById(R.id.step_content_tv);
        itemView.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int clickedPosition = getAdapterPosition();
        clickListener.onItemClick(clickedPosition);
    }
}

public interface ClickListener{
    void onItemClick(int clickedItemPosition);
}

```

}

Layout files are as I already explained above. I guess nothing special to post here.

Thanks in advance.