title: How to get item from Recycler View?
body: <p>I created list using Recycler View. Now I want to get item after click. I heard about getAdapterPosition but I dont know how to use it.
  I try something like this but honestly dont know how to get it.</p>
  <p>My Fragment class code:</p>
  <pre><code>public class FragmentOne extends Fragment {
  
      private static RecyclerView.Adapter adapter;
      private RecyclerView.LayoutManager layoutManager;
      private static RecyclerView recyclerView;
      private List&lt;MovieDb&gt; data;
      private MovieDb movieDb;
      static View.OnClickListener myOnClickListener;
  
      public static FragmentOne newInstance() {
          FragmentOne fragment = new FragmentOne();
          return fragment;
      }
  
      public class MovieTask extends AsyncTask&lt;Void, Void, List&lt;MovieDb&gt;&gt; {
          @Override
          protected List&lt;MovieDb&gt; doInBackground(Void... voids) {
              MovieResultsPage movies = new TmdbApi(&quot;f753872c7aa5c000e0f46a4ea6fc49b2&quot;).getMovies().getUpcoming(&quot;en-US&quot;, 1, &quot;US&quot;);
              List&lt;MovieDb&gt; listMovies = movies.getResults();
  
              return listMovies;
          }
  
          @Override
          protected void onPostExecute(List&lt;MovieDb&gt; movieDb) {
              data = movieDb;
              adapter = new CustomAdapter(data);
              recyclerView.setAdapter(adapter);
          }
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View returnView = inflater.inflate(R.layout.fragment_one, container, false);
  
          myOnClickListener = new MyOnClickListener(getContext());
  
          recyclerView = (RecyclerView) returnView.findViewById(R.id.my_recycler_view);
          recyclerView.setHasFixedSize(true);
  
          layoutManager = new LinearLayoutManager(getContext());  // ???
          recyclerView.setLayoutManager(layoutManager);
          recyclerView.setItemAnimator(new DefaultItemAnimator());
  
          MovieTask mt = new MovieTask();
          mt.execute();
  
          return returnView;
      }
  
      private class MyOnClickListener implements View.OnClickListener {
  
          private final Context context;
  
          private MyOnClickListener(Context context) {
              this.context = context;
          }
  
          @Override
          public void onClick(View v) {
              int pos1;
              pos1 = adapter.getItemId();
              movieDb = data.get(pos);
              TextView text;
              text = (TextView) v.findViewById(R.id.text1);
              Toast.makeText(getActivity(), text.getText(), LENGTH_SHORT).show();
          }
  
      }
  }
  </code></pre>
  <p>Function OnClick is mess because I try a lot. I can get text from TextView but it is not what I want.</p>
  <p>There is my Adapter class:</p>
  <pre><code>public class CustomAdapter extends RecyclerView.Adapter&lt;CustomAdapter.MyViewHolder&gt; {
  
      private List&lt;MovieDb&gt; dataSet;
      public int pos;
  
      public static class MyViewHolder extends RecyclerView.ViewHolder {
  
          TextView textViewName;
          TextView textViewVersion;
          ImageView imageViewIcon;
          int pos;
  
          public MyViewHolder(View itemView) {
              super(itemView);
              this.textViewName = (TextView) itemView.findViewById(R.id.text1);
              this.textViewVersion = (TextView) itemView.findViewById(R.id.text2);
              this.imageViewIcon = (ImageView) itemView.findViewById(R.id.imageView);
              itemView.setOnClickListener(FragmentOne.myOnClickListener);
          }
      }
  
      public CustomAdapter(List&lt;MovieDb&gt; data) {
          this.dataSet = data;
      }
  
  
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent,
                                             int viewType) {
          View view = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.cards_layout, parent, false);
  
          //view.setOnClickListener(FragmentOne.myOnClickListener);
  
          MyViewHolder myViewHolder = new MyViewHolder(view);
          return myViewHolder;
      }
  
      @Override
      public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
  
          TextView textViewName = holder.textViewName;
          TextView textViewVersion = holder.textViewVersion;
          pos = holder.getAdapterPosition();
          ImageView imageView = holder.imageViewIcon;
          Glide.with(imageView).load(&quot;https://image.tmdb.org/t/p/w500&quot; + dataSet.get(listPosition).getPosterPath()).into(imageView);
  
          textViewName.setText(dataSet.get(listPosition).getOriginalTitle());
          textViewVersion.setText(dataSet.get(listPosition).getReleaseDate());
      }
  
      public int getPos(){
          return pos;
      }
  
      @Override
      public int getItemCount() {
          if(dataSet == null){
              return 0;
          }
          return dataSet.size();
      }
  }
  </code></pre>
  <p>I try to get position using <code>int pos</code> but I dont know how to use it in function OnClick.</p>