title: how to use getItematposition() in recyclerview adapter as ListView
body: <p>I have a <code>RecyclerViewAdapter</code> which fill my List with StoreName,image etc, I had model for listitems.ok, I'm migrating from a ListView to recylerview. i want to click on any item and get that items data(like Store name) and intent to another activity, now problem is that when i click on item it give wrong storename. but when i was using onItemclickListener that provide correct input. i will show u.. </p>
  
  <p>This my <strong>RecyclerViewAdapter</strong>.</p>
  
  <pre><code> public class MyRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyRecyclerViewAdapter.DataObjectHolder&gt; {
      private static String LOG_TAG = "MyRecyclerViewAdapter";
      private List&lt;StoresItem&gt; mDataset;
      private static MyClickListener myClickListener;
      Context context;
  
      Bitmap xx;
  
      public MyRecyclerViewAdapter(Context context, List&lt;StoresItem&gt; myDataset)
      {
          mDataset = myDataset;
      }
  
      public static class DataObjectHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
          TextView txtStoreName,txtDeliveryTime;
          ImageView storeImg;
          RatingBar ratingBar;
  
  
  
          public DataObjectHolder(View itemView)
          {
  
  
              super(itemView);
              txtStoreName = (TextView) itemView.findViewById(R.id.txtStoreName);
              txtDeliveryTime = (TextView) itemView.findViewById(R.id.txtDeliveryTime);
              storeImg = (ImageView) itemView.findViewById(R.id.storeImg);
              ratingBar=(RatingBar)itemView.findViewById(R.id.ratingBar);
              Log.i(LOG_TAG, "Adding Listener");
              itemView.setOnClickListener(this);
          }
  
          @Override
          public void onClick(View v)
          {
  
              myClickListener.onItemClick(getLayoutPosition(), v);
          }
      }
  
  
  
      public void setOnItemClickListener(MyClickListener myClickListener)
      {
          this.myClickListener = myClickListener;
      }
  
  
  
      @Override
      public DataObjectHolder onCreateViewHolder(ViewGroup parent, int viewType)
      {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.storelist, parent, false);
  
          DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
          return dataObjectHolder;
      }
  
      @Override
      public void onBindViewHolder(DataObjectHolder holder, int position)
      {
  
          ImageView storeImg;
  
          holder.txtStoreName.setText(mDataset.get(position).gettxtStoreName().toString());
          holder.txtDeliveryTime.setText(mDataset.get(position).gettxtDeliveryTime().toString());
          holder.ratingBar.setFocusable(false);
  
  
          int loader = R.drawable.image;
  
          String url = mDataset.get(position).getstoreImg().toString();
  
          ImageLoader imgLoader = new ImageLoader(context);
  
          imgLoader.DisplayImage(url,loader,holder.storeImg);
  
  
      }
  
  
  
      public void addItem(StoresItem dataObj, int index) {
          mDataset.add(dataObj);
          notifyItemInserted(index);
      }
  
      public void deleteItem(int index) {
          mDataset.remove(index);
          notifyItemRemoved(index);
      }
  
      @Override
      public int getItemCount() {
          return mDataset.size();
      }
  
      public interface MyClickListener
      {
          public void onItemClick(int position, View v);
      }
  
      public Object getItem(int position)
      {
          return mDataset.get(position);
      }
  
      @Override
      public long getItemId(int position)
      {
          return mDataset.indexOf(getItem(position));
      }
  
  
      @Override
      public int getItemViewType(int position)
      {
          return super.getItemViewType(position);
      }
  }
  </code></pre>
  
  <p>This is my <strong>StoreModel</strong>.</p>
  
  <pre><code>public class StoresItem
  {
          private String txtStoreName, txtDeliveryTime, storeImg;
  
          public StoresItem(String txtStoreName, String txtDeliveryTime,String storeImg)
          {
  
              this.txtStoreName = txtStoreName;
              this.txtDeliveryTime = txtDeliveryTime;
              this.storeImg = storeImg;
  
          }
  
      public String gettxtStoreName()
      {
          return txtStoreName;
      }
  
      public void settxtStoreName(String txtStoreName)
      {
          this.txtStoreName = txtStoreName;
      }
  
      public String gettxtDeliveryTime()
      {
          return txtDeliveryTime;
      }
  
      public void settxtDeliveryTime(String txtDeliveryTime)
      {
          this.txtDeliveryTime = txtDeliveryTime;
      }
  
      public String getstoreImg()
      {
          return storeImg;
      }
  
      public void setstoreImg(String storeImg)
      {
          this.storeImg = storeImg;
      }
  
  
  }
  </code></pre>
  
  <p>And this is my Fragment where i using <strong>onclickListner</strong>.</p>
  
  <pre><code> public class RecylerFragment extends Fragment
  {
  
      ListView storeListView;
      List&lt;StoresItem&gt; storesItem;
      StoresListAdaptor adapter;
      String selectedStore;
  
      private RecyclerView mRecyclerView;
      private RecyclerView.Adapter mAdapter;
      private RecyclerView.LayoutManager mLayoutManager;
  
  
  
      public static final String[] storeNameGrocery = new String[]
              {
                      "Value Store", "Grocery Mart", "Wild Water-Sadar Bazar", "Store99","Coco-Buzz", "Wild Water - Sector 46"
              };
      public static final String[] storeNameFresh = new String[]
              {
                      "Mother's Love", "The Flower Shop", "Flower N Emotions"
              };
      public static final String[] storeNameElectronics = new String[]
              {
                      "Molife-Sheetla Mata Road", "Apple Store- Shona Road", "Vandana Communication", "Samsung Store","JMD Mobile - Sector 14", "Sterling - Gurgaon"
              };
      public static final String[] storeNameVegetable = new String[]
              {
                      "Fortune Store", "Best Food - Mega Mall", "Sadar Bazar", "MTR Store","Coco-Buzz"
              };
  
      public static final String[] deliveryTime = new String[]
              {
                      "20min", "10min", "9min", "15min","30min", "1hr","20min","20min", "10min", "9min", "15min","30min", "1hr","20min" };
  
  
      private static final String KEY_POSITION="position";
  
  
  
      public static final String[] iconsUrl = new String[]
              {
                      "http://icons.iconarchive.com/icons/femfoyou/angry-birds/96/angry-bird-icon.png",
                      "http://icons.iconarchive.com/icons/rokey/the-blacy/96/grimace-icon.png",
                      "http://wcdn1.dataknet.com/static/resources/icons/set106/fec007de.png",
                      "http://cdn4.aptoide.com/imgs/7/6/e/76e0376928b8393227a150fbed5d6b4a_icon_96x96.png",
                      "http://vaivocabulary.com/vai/images/android.png",
                      "http://cdn4.aptoide.com/imgs/7/6/e/76e0376928b8393227a150fbed5d6b4a_icon_96x96.png",
                      "http://vaivocabulary.com/vai/images/android.png",
                      "http://wcdn1.dataknet.com/static/resources/icons/set106/fec007de.png",
              };
  
  
      public RecylerFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
      {
          View rootView = inflater.inflate(R.layout.activity_recycler_view, container, false);
  
  
          Bundle bundle = this.getArguments();
          String myString = bundle.getString("page_position");
  
          mRecyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
          mRecyclerView.setHasFixedSize(true);
          mLayoutManager = new LinearLayoutManager(getActivity());
          mRecyclerView.setLayoutManager(mLayoutManager);
  
  
          RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL);
          mRecyclerView.addItemDecoration(itemDecoration);
  
          // Code to Add an item with default animation
          //((MyRecyclerViewAdapter) mAdapter).addItem(obj, index);
  
          // Code to remove an item with default animation
          //((MyRecyclerViewAdapter) mAdapter).deleteItem(index);
  
  
          storesItem = new ArrayList&lt;StoresItem&gt;();
  
          if(myString.equals("999")) {
              for (int i = 0; i &lt; storeNameGrocery.length; i++) {
                  StoresItem item = new StoresItem(storeNameGrocery[i], "Delivery Time " + deliveryTime[i],iconsUrl[i]);
                  storesItem.add(item);
              }
          }
  
          else if(myString.equals("888")) {
              for (int i = 0; i &lt; storeNameFresh.length; i++) {
                  StoresItem item = new StoresItem(storeNameFresh[i], "Delivery Time " + deliveryTime[i], iconsUrl[i]);
                  storesItem.add(item);
              }
          }
  
          else if(myString.equals("777")) {
              for (int i = 0; i &lt; storeNameElectronics.length; i++) {
                  StoresItem item = new StoresItem(storeNameElectronics[i], "Delivery Time " + deliveryTime[i], iconsUrl[i]);
                  storesItem.add(item);
              }
          }
  
          else if(myString.equals("666")) {
              for (int i = 0; i &lt; storeNameVegetable.length; i++) {
                  StoresItem item = new StoresItem(storeNameVegetable[i], "Delivery Time " + deliveryTime[i], iconsUrl[i]);
                  storesItem.add(item);
              }
          }
  
          mAdapter = new MyRecyclerViewAdapter(getActivity(), storesItem);
          mRecyclerView.setAdapter(mAdapter);
  
  
  
  
          return rootView;
      }
  
  
      **@Override
      public void onResume() {
          super.onResume();
          ((MyRecyclerViewAdapter) mAdapter).setOnItemClickListener(new MyRecyclerViewAdapter.MyClickListener()
          {
          @Override
           public void onItemClick(int position, View v)
          {
              System.out.println(" Clicked on Item " + position);
              StoresItem storesItems = (StoresItem) ((MyRecyclerViewAdapter) mAdapter).getItem(position);
              Bundle args = new Bundle();
              Intent in = new Intent(getActivity(), ProductActivity.class);
              args.putString("SelectedStoreName", storesItems.gettxtStoreName().toString());
              in.putExtras(args);
              startActivity(in);
          }
         });
      }**
  
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
      }
  }
  </code></pre>
  
  <p>okk...there is something wrong with recyclerviews-<code>onItemclicklister</code> because listviews - <code>onItemCLicklistner()</code>
    provide <code>Adapterview</code> and i can simply get Item by using <code>parent.getItematposition(position)</code> like this.</p>
  
  <pre><code> storeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              StoresItem storesItems = (StoresItem) parent.getItemAtPosition(position);
              Bundle args = new Bundle();
              Intent in = new Intent(getActivity(), ProductActivity.class);
              args.putString("SelectedStoreName", storesItems.gettxtStoreName().toString());
              in.putExtras(args);
              startActivity(in);
  
          }
      });
  </code></pre>
  
  <p>Can Any one tell me whats the reason why getWrong StoreName.??</p>