title: add SharedPreferences to items in Recycler adapter
body: <p>I want to be able to check in other Activities if items in the RecyclerView are checked and don't know how to do that.
  I tried it with SharedPreferences, but only get an null object reference.</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
          at com.icedex.lolmon.testapp.firststart.FirstStartRecyclerAdapter$ViewHolder.&lt;init&gt;(FirstStartRecyclerAdapter.java:63)
          at com.icedex.lolmon.testapp.firststart.FirstStartRecyclerAdapter.onCreateViewHolder(FirstStartRecyclerAdapter.java:35)
          at com.icedex.lolmon.testapp.firststart.FirstStartRecyclerAdapter.onCreateViewHolder(FirstStartRecyclerAdapter.java:18)
          at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5116)
          at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4416)
          at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
          at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
          at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:437)
          at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
          at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
          at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:171)
          at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2713)
          at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3011)
          at android.view.View.layout(View.java:15671)
          at android.view.ViewGroup.layout(ViewGroup.java:5038)
          at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1626)
          at android.view.View.layout(View.java:15671)
          at android.view.ViewGroup.layout(ViewGroup.java:5038)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
          at android.view.View.layout(View.java:15671)
          at android.view.ViewGroup.layout(ViewGroup.java:5038)
          at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
          at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
          at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
          at android.view.View.layout(View.java:15671)
          at android.view.ViewGroup.layout(ViewGroup.java:5038)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
          at android.view.View.layout(View.java:15671)
          at android.view.ViewGroup.layout(ViewGroup.java:5038)
          at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
          at android.view.Choreographer.doCallbacks(Choreographer.java:580)
          at android.view.Choreographer.doFrame(Choreographer.java:550)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5254)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>This is my Code:</p>
  
  <pre><code>public class FirstStartRecyclerAdapter extends RecyclerView.Adapter&lt;FirstStartRecyclerAdapter.ViewHolder&gt; {
  
  public static final String TAG = "FSRecyclerAdapter";
  public ArrayList&lt;Card&gt; cards;
  public Context context;
  
  public SharedPreferences sharedPref;
  
  public boolean checkMusic = false;
  
  public FirstStartRecyclerAdapter(Context context, ArrayList&lt;Card&gt; cards) {
      this.cards = cards;
      this.context = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
  
      return new ViewHolder(itemView);
  }
  
  @Override
  public void onBindViewHolder(FirstStartRecyclerAdapter.ViewHolder holder, int position) {
  
      Card card = cards.get(position);
      holder.card_tv.setText(card.cardName);
      holder.card_iv.setImageResource(card.getDrawable());
      holder.card_iv2.setImageResource(card.getDrawable2());
  }
  
  public int getItemCount() {
          return cards.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
      public ImageView card_iv;
      public ImageView card_iv2;
      public TextView card_tv;
  
      public ViewHolder(View itemView) {
          super(itemView);
          card_tv = (TextView) itemView.findViewById(R.id.card_tv);
          card_iv = (ImageView) itemView.findViewById(R.id.card_iv);
          card_iv2 = (ImageView) itemView.findViewById(R.id.card_iv2);
  
          itemView.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View view) {
          int position = getLayoutPosition();
          Log.d(TAG, "clicked position:" + position);
          long postId = cards.get(position).getId();
  
          sharedPref = context.getSharedPreferences("myPref", Context.MODE_PRIVATE);
          SharedPreferences.Editor edit = sharedPref.edit();
  
          edit.putBoolean("checkWear", false);
          edit.apply();
  
          if (postId == 1) {
  
              if (sharedPref.getBoolean("checkWear", true)) {
                  card_iv2.setImageResource(R.drawable.checkbox_blank_circle_outline);
                  edit.putBoolean("checkWear", false);
                  edit.apply();
              } else {
                  card_iv2.setImageResource(R.drawable.checkbox_marked_circle);
                  edit.putBoolean("checkWear", true);
                  edit.apply();
              }
          }
  
          if (postId == 2) {
  
              if (checkMusic) {
                  card_iv2.setImageResource(R.drawable.checkbox_blank_circle_outline);
                  checkMusic = false;
              } else {
                  card_iv2.setImageResource(R.drawable.checkbox_marked_circle);
                  checkMusic = true;
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>I would appreciate any help.</p>