title: How to save state when item is Clicked in Android recyclerVIew
body: <p>I have created a recyclerView and handle items in it being clicked. Now I need to change the text displayed when one item is clicked. First it says 'day' and after I click it it should say 'finished'. It worked but after I close and re-open the activity it says 'day' again. So what do I need to do to make the item text persist? </p>
  
  <pre><code>  private OnFragmentInteractionListener mListener;
      List&lt;String&gt; list;
      MyListAdapter adapter;
      RecyclerView recyclerView;
      String pressed="finished";
   public MainFragment() {
          // Required empty public constructor
      }
  
  @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View rootView= inflater.inflate(R.layout.fragment_main, container, false);
  
          recyclerView=(RecyclerView)rootView.findViewById(R.id.item_list);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  
          list=new ArrayList&lt;&gt;();
          for(int i=1;i&lt;50;i++){
              list.add("Day"+ i);
          }
  
          adapter =new MyListAdapter(getActivity(),list,this);
          recyclerView.setAdapter(adapter);
  
  
          return rootView;
  
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
          mListener = null;
      }
  
      @Override
      public void onNoteClick(int position) {
          if (position == 0) {
              Log.d(TAG, "onNoteClick: ");
              list.set(0, "finished");
              adapter.getItemId(0);
  
  
              adapter.notifyItemChanged(0);
              adapter.notifyDataSetChanged();
  
  
  
  
  
  
  
              Fragment fr = new Day1();
              FragmentManager fm = getFragmentManager();
              FragmentTransaction fragmentTransaction = fm.beginTransaction();
              fragmentTransaction.replace(R.id.Mainfragment1, fr,null).addToBackStack(null);
              fragmentTransaction.commit();
  
          }
  
      }
  </code></pre>
  
  <p>And adapter code</p>
  
  <pre><code> Context context;
  List&lt;String&gt;list;
  public TextView textView;
  public String finished="finished";
  private MyViewHolder.OnNoteClickListener mOnNoteClickListener;
  
  public MyListAdapter(Context context, List&lt;String&gt;list, MyViewHolder.OnNoteClickListener onNoteClickListener) {
      this.list=list;
      this.context=context;
      this.mOnNoteClickListener=onNoteClickListener;
  }
  
  public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
      Button textView;
  
  
      OnNoteClickListener onNoteClickListener;
  
      public MyViewHolder(View itemView,OnNoteClickListener onNoteClickListener) {
          super(itemView);
          textView=(Button) itemView.findViewById(R.id.textView);
          itemView.setOnClickListener(this);
          textView.setOnClickListener(this);
          this.onNoteClickListener=onNoteClickListener;
  
  
          itemView.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          onNoteClickListener.onNoteClick(getAdapterPosition());
  
  
  
  
  
      }
  
  
  
      public interface OnNoteClickListener{
          void onNoteClick(int position);
  
      }
  }
  
  @NonNull
  @Override
  public MyViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
      View view= LayoutInflater.from(context).inflate(R.layout.layout_list_item,parent,false);
      final MyViewHolder vHolder=new MyViewHolder(view,mOnNoteClickListener);
  
      return vHolder;
  
  }
  
  @Override
  public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
      holder.textView.setText(list.get(position));
  
  
  
  
  }
  
  @Override
  public int getItemCount() {
      return list.size();
  }
  </code></pre>
  
  <p>}</p>