title: How to highlight a selected RecyclerView item and use its values in Activity
body: <p>I have a list of words with translations in RecyclerView. I want the selected word to be highlighted, but at the same time I could use these values in Activity. I can highlight selected values <strong>or</strong> use the values of a selected item, <strong>but the combination of the both fails.</strong>
  Please, maybe You see where I am wrong and can help solve my problem.</p>
  <p>p.s. Please don’t judge me for the not enough clean code and my English, I’m learning. :)</p>
  <p><strong>MyListActivity.java</strong></p>
  <pre><code>public class MyListActivity extends AppCompatActivity {
  
      public ArrayList&lt;MyWord&gt; myWordList = new ArrayList&lt;&gt;();
      SelectData sd = new SelectData();
      int wordId;
      String word;
      String translation;
  
      public RecyclerView mRecycleView;
      public MyAdapter mAdapter;
      public RecyclerView.LayoutManager mLayoutManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my_list);
  
          sd.selectMyWords(myWordList);
  
          buildRecycleView();
  
          Button btnInsert = findViewById(R.id.mywords_button_insert);
          Button btnEdit = findViewById(R.id.mywords_button_edit);
          Button btnDelete = findViewById(R.id.mywords_button_delete);
          Button btnMain = findViewById(R.id.mywords_button_backttomain);
  
          mAdapter.setOnItemClickListener(new MyAdapter.OnItemClickListener() {
              @Override
              public void onItemClick(int position) {
  
  // **This is my selected item values**
  
                  wordId = myWordList.get(position).getWordId(); 
                  word = myWordList.get(position).getWord();
                  translation = myWordList.get(position).getTranslation();
                  
                  Toast.makeText(MyListActivity.this, &quot;Selected -&gt; &quot; + word, Toast.LENGTH_SHORT).show();
              }
          });
  
          btnEdit.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if(!(word == null)) {
                      Intent intentInsert = new Intent(MyListActivity.this, InsertActivity.class);
                      intentInsert.putExtra(&quot;W&quot;, word);
                      intentInsert.putExtra(&quot;TR&quot;, translation);
                      intentInsert.putExtra(&quot;ACTION&quot;, &quot;ED&quot;);
                      startActivity(intentInsert);
                  } else {
                      Toast.makeText(MyListActivity.this, &quot;Select word&quot;, Toast.LENGTH_SHORT).show();
                  }
              }
          });
  
      }
  
      @Override
      public void onBackPressed() {
          super.onBackPressed();
          
      }
  
      public void buildRecycleView(){
          mRecycleView = findViewById(R.id.mywords_RecycleView);
          mRecycleView.setHasFixedSize(true);
          mLayoutManager = new LinearLayoutManager(this);
          mAdapter = new MyAdapter(myWordList);
  
          mRecycleView.setLayoutManager(mLayoutManager);
          mRecycleView.setAdapter(mAdapter);
  
          if (myWordList.isEmpty()){
              Toast.makeText(this, &quot;word list is empty&quot;, Toast.LENGTH_SHORT).show();
          }
      }
  }
  
  </code></pre>
  <p><strong>MyAdapter.java</strong></p>
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt; {
      private ArrayList&lt;MyWord&gt; mMyWordList;
      private OnItemClickListener mListener;
  
      public interface OnItemClickListener{
          void onItemClick(int position);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener){
          mListener = listener;
      }
  
      public static class MyViewHolder extends RecyclerView.ViewHolder {
  
          public TextView mTextViewEN;
          public TextView mTextViewLT;
          public ImageView imageViewLearned;
  
          public MyViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
              super(itemView);
              mTextViewEN = itemView.findViewById(R.id.myList_textView_word);
              mTextViewLT = itemView.findViewById(R.id.myList_textView_translation);
              imageViewLearned = itemView.findViewById(R.id.iV_learned);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if (listener != null){
                          int position = getAdapterPosition();
                          if (position != RecyclerView.NO_POSITION){
                              listener.onItemClick(position);
                          }
                      }
                  }
              });
          }
      }
  
      public MyAdapter(ArrayList&lt;MyWord&gt; myWordList){
         mMyWordList = myWordList;
      }
  
      int selectedItem = -1;
     
      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
         View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_list_view_layout, parent, false);
          MyViewHolder mvh = new MyViewHolder(v, mListener);
          return mvh;
      }
  
      @Override
      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
  
          MyWord currentMyWord = mMyWordList.get(position);
          holder.mTextViewEN.setText(currentMyWord.getWord());
          holder.mTextViewLT.setText(currentMyWord.getTranslation());
  
  // TODO - START (select item highlight) - if I activate highlighting, the assignment of values no longer works in MyListActivity.
          
        /*  holder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  selectedItem = position;
                  notifyDataSetChanged();
              }
          });
  
          if (selectedItem == position) {
              holder.itemView.setBackgroundColor(Color.parseColor(&quot;#C0C0C0&quot;));
          } else {
              holder.itemView.setBackgroundColor(Color.parseColor(&quot;#F8F8F8&quot;));
          } */
  //TODO -END
  
      }
  
      @Override
      public int getItemCount() {
          return mMyWordList.size();
      }
  }
  </code></pre>