title: Select only one image in RecyclerView
body: <p>I have a <code>RecyclerView.Adapter</code> which has some Arrays there.</p>
  
  <p>ArrayList with Strings and ArrayList with Integer. Strings are like url and Integer is the photo.</p>
  
  <p>When the app is open for first time the first item is selected.
  I have another method for click which makes another item as selected and this works, but the problem is that the first item stays as selected and so for every image click makes as selected, I want only one item to be selected and take a color.</p>
  
  <p>This is my code.</p>
  
  <p>Adapter of RecyclerView</p>
  
  <pre><code>public class ListViewAdapter extends RecyclerView.Adapter&lt;ListViewAdapter.ViewHolder&gt;{
      private int selectedItem;
  
      private ArrayList&lt;Integer&gt; mImages = new ArrayList&lt;&gt;();
      private ArrayList&lt;String&gt; mSearchUrl = new ArrayList&lt;&gt;();
      private Context mContext;
  
      public ListViewAdapter(ArrayList&lt;Integer&gt; images, ArrayList&lt;String&gt; SearchUrl, Context context) {
          mImages = images;
          mContext = context;
          mSearchUrl = SearchUrl;
      }
      @NonNull
      @Override
      public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
          View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.s_engine_item, viewGroup, false);
  
          return new ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int i) {
          selectedItem = 0;
          if (selectedItem == i) {
              viewHolder.image.setBackgroundColor(Color.parseColor("#30000000"));
          }
          Glide.with(mContext).load(mImages.get(i))
                  .into(viewHolder.image);
          viewHolder.searchUrl.setText(mSearchUrl.get(i));
  
          viewHolder.image.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  viewHolder.image.setBackgroundColor(Color.parseColor("#30000000"));
                  selectedItem = i;
  
              }
          });
  
      }
  
      @Override
      public int getItemCount() {
          return mImages.size();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder{
  
          ImageView image;
          TextView searchUrl;
  
          public ViewHolder(@NonNull View itemView) {
              super(itemView);
              image = itemView.findViewById(R.id.ivEngine);
              searchUrl = itemView.findViewById(R.id.ivEngineText);
          }
      }
  }
  </code></pre>
  
  <p>And this is the MainActivity.class</p>
  
  <pre><code>public void intSearch() {
      mImages.add(R.drawable.s_bing);
      mSearchUrl.add("https://www.bing.com/search?q=");
  
      mImages.add(R.drawable.s_google);
      mSearchUrl.add("https://www.google.com/search?q=");
  
      mImages.add(R.drawable.s_yahoo);
      mSearchUrl.add("www.yahoo.com");
  
      mImages.add(R.drawable.amazon_white256);
      mSearchUrl.add("www.amazon.com");
  
      mImages.add(R.drawable.amazon_white256);
      mSearchUrl.add("www.amazon.com");
  
      mImages.add(R.drawable.amazon_white256);
      mSearchUrl.add("www.amazon.com");
  
      initRecyclerView();
  }
  private void initRecyclerView() {
      LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
      RecyclerView recyclerView = findViewById(R.id.lvEngines);
      recyclerView.setLayoutManager(layoutManager);
      ListViewAdapter adapter = new ListViewAdapter(mImages, mSearchUrl, this);
      recyclerView.setAdapter(adapter);
  }
  </code></pre>