RecyclerView with 3 by 3 item Horizontal scroll












0















In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image



enter image description here



I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it










share|improve this question























  • Basically, you're asking for opinions on which component to use in this situation?

    – Shark
    Nov 20 '18 at 18:04











  • Yes which is best option to use or any other components i can use for this situation

    – Jagan
    Nov 20 '18 at 19:38
















0















In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image



enter image description here



I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it










share|improve this question























  • Basically, you're asking for opinions on which component to use in this situation?

    – Shark
    Nov 20 '18 at 18:04











  • Yes which is best option to use or any other components i can use for this situation

    – Jagan
    Nov 20 '18 at 19:38














0












0








0








In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image



enter image description here



I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it










share|improve this question














In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image



enter image description here



I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it







android android-recyclerview android-viewpager pagersnaphelper






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 17:38









JaganJagan

4721130




4721130













  • Basically, you're asking for opinions on which component to use in this situation?

    – Shark
    Nov 20 '18 at 18:04











  • Yes which is best option to use or any other components i can use for this situation

    – Jagan
    Nov 20 '18 at 19:38



















  • Basically, you're asking for opinions on which component to use in this situation?

    – Shark
    Nov 20 '18 at 18:04











  • Yes which is best option to use or any other components i can use for this situation

    – Jagan
    Nov 20 '18 at 19:38

















Basically, you're asking for opinions on which component to use in this situation?

– Shark
Nov 20 '18 at 18:04





Basically, you're asking for opinions on which component to use in this situation?

– Shark
Nov 20 '18 at 18:04













Yes which is best option to use or any other components i can use for this situation

– Jagan
Nov 20 '18 at 19:38





Yes which is best option to use or any other components i can use for this situation

– Jagan
Nov 20 '18 at 19:38












1 Answer
1






active

oldest

votes


















-1














For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.





  1. The first Step you should add Viewpager in parent xml :


    activity_main.xml






    <ImageView
    android:id="@+id/left_arrow"
    android:layout_width="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignTop="@+id/view_pager"
    android:rotation="180"
    android:padding="8dp"
    android:layout_alignBottom="@id/view_pager"
    android:src="@drawable/ic_arrow"/>

    <android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:id="@+id/view_pager"
    android:layout_toLeftOf="@id/right_arrow"
    android:layout_toRightOf="@id/left_arrow"
    android:layout_height="150dp"/>

    <com.rd.PageIndicatorView
    android:id="@+id/pageIndicatorView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/view_pager"
    app:piv_animationType="worm"
    app:piv_dynamicCount="true"
    android:layout_marginTop="10dp"
    android:layout_centerHorizontal="true"
    app:piv_interactiveAnimation="true"
    app:piv_radius="3dp"
    app:piv_unselectedColor="#999999"
    app:piv_selectedColor="#000000"
    app:piv_viewPager="@id/view_pager"
    attrs:piv_padding="8dp" />
    <ImageView
    android:id="@+id/right_arrow"
    android:padding="8dp"
    android:layout_alignTop="@+id/view_pager"
    android:layout_alignBottom="@id/view_pager"
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_centerVertical="true"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_arrow"/>





  2. In this step you should create Viewpager adapter :


    pageAdapter.kt



    override fun getItem(position: Int): Fragment {
    val firstItem = ((position + 1) * 3) - 2
    val lastItem = ((position + 1) * 3)
    val itemSet = arrayListOf<String>()
    for (i in firstItem..lastItem) {
    if (i <= items.size)
    itemSet.add(items[i - 1])
    }
    return ItemFragment.newInstance(itemSet)
    }

    override fun getCount(): Int {
    return size
    }



  3. In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :


    ItemFragment



    // Creates the view controlled by the fragment
    val view = inflater.inflate(R.layout.page, container, false)
    val recycler = view.findViewById<RecyclerView>(R.id.recycler)

    // Retrieve and display the movie data from the Bundle
    val args = arguments
    recycler.layoutManager = GridLayoutManager(activity,3)
    recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)



  4. And The Last Just create RecyclerAdapter and show data to each item in list:


    ItemAdapter.kt



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    holder?.title?.text = items.get(position)
    }

    override fun getItemCount(): Int {
    return items.size
    }


    Result :

    enter image description here




if you want to see the full source, just go to this link






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398561%2frecyclerview-with-3-by-3-item-horizontal-scroll%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.





    1. The first Step you should add Viewpager in parent xml :


      activity_main.xml






      <ImageView
      android:id="@+id/left_arrow"
      android:layout_width="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:layout_alignTop="@+id/view_pager"
      android:rotation="180"
      android:padding="8dp"
      android:layout_alignBottom="@id/view_pager"
      android:src="@drawable/ic_arrow"/>

      <android.support.v4.view.ViewPager
      android:layout_width="match_parent"
      android:id="@+id/view_pager"
      android:layout_toLeftOf="@id/right_arrow"
      android:layout_toRightOf="@id/left_arrow"
      android:layout_height="150dp"/>

      <com.rd.PageIndicatorView
      android:id="@+id/pageIndicatorView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/view_pager"
      app:piv_animationType="worm"
      app:piv_dynamicCount="true"
      android:layout_marginTop="10dp"
      android:layout_centerHorizontal="true"
      app:piv_interactiveAnimation="true"
      app:piv_radius="3dp"
      app:piv_unselectedColor="#999999"
      app:piv_selectedColor="#000000"
      app:piv_viewPager="@id/view_pager"
      attrs:piv_padding="8dp" />
      <ImageView
      android:id="@+id/right_arrow"
      android:padding="8dp"
      android:layout_alignTop="@+id/view_pager"
      android:layout_alignBottom="@id/view_pager"
      android:layout_alignParentRight="true"
      android:layout_width="wrap_content"
      android:layout_centerVertical="true"
      android:layout_height="wrap_content"
      android:src="@drawable/ic_arrow"/>





    2. In this step you should create Viewpager adapter :


      pageAdapter.kt



      override fun getItem(position: Int): Fragment {
      val firstItem = ((position + 1) * 3) - 2
      val lastItem = ((position + 1) * 3)
      val itemSet = arrayListOf<String>()
      for (i in firstItem..lastItem) {
      if (i <= items.size)
      itemSet.add(items[i - 1])
      }
      return ItemFragment.newInstance(itemSet)
      }

      override fun getCount(): Int {
      return size
      }



    3. In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :


      ItemFragment



      // Creates the view controlled by the fragment
      val view = inflater.inflate(R.layout.page, container, false)
      val recycler = view.findViewById<RecyclerView>(R.id.recycler)

      // Retrieve and display the movie data from the Bundle
      val args = arguments
      recycler.layoutManager = GridLayoutManager(activity,3)
      recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)



    4. And The Last Just create RecyclerAdapter and show data to each item in list:


      ItemAdapter.kt



      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
      }

      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      holder?.title?.text = items.get(position)
      }

      override fun getItemCount(): Int {
      return items.size
      }


      Result :

      enter image description here




    if you want to see the full source, just go to this link






    share|improve this answer






























      -1














      For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.





      1. The first Step you should add Viewpager in parent xml :


        activity_main.xml






        <ImageView
        android:id="@+id/left_arrow"
        android:layout_width="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignTop="@+id/view_pager"
        android:rotation="180"
        android:padding="8dp"
        android:layout_alignBottom="@id/view_pager"
        android:src="@drawable/ic_arrow"/>

        <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:id="@+id/view_pager"
        android:layout_toLeftOf="@id/right_arrow"
        android:layout_toRightOf="@id/left_arrow"
        android:layout_height="150dp"/>

        <com.rd.PageIndicatorView
        android:id="@+id/pageIndicatorView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view_pager"
        app:piv_animationType="worm"
        app:piv_dynamicCount="true"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        app:piv_interactiveAnimation="true"
        app:piv_radius="3dp"
        app:piv_unselectedColor="#999999"
        app:piv_selectedColor="#000000"
        app:piv_viewPager="@id/view_pager"
        attrs:piv_padding="8dp" />
        <ImageView
        android:id="@+id/right_arrow"
        android:padding="8dp"
        android:layout_alignTop="@+id/view_pager"
        android:layout_alignBottom="@id/view_pager"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_arrow"/>





      2. In this step you should create Viewpager adapter :


        pageAdapter.kt



        override fun getItem(position: Int): Fragment {
        val firstItem = ((position + 1) * 3) - 2
        val lastItem = ((position + 1) * 3)
        val itemSet = arrayListOf<String>()
        for (i in firstItem..lastItem) {
        if (i <= items.size)
        itemSet.add(items[i - 1])
        }
        return ItemFragment.newInstance(itemSet)
        }

        override fun getCount(): Int {
        return size
        }



      3. In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :


        ItemFragment



        // Creates the view controlled by the fragment
        val view = inflater.inflate(R.layout.page, container, false)
        val recycler = view.findViewById<RecyclerView>(R.id.recycler)

        // Retrieve and display the movie data from the Bundle
        val args = arguments
        recycler.layoutManager = GridLayoutManager(activity,3)
        recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)



      4. And The Last Just create RecyclerAdapter and show data to each item in list:


        ItemAdapter.kt



        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
        }

        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder?.title?.text = items.get(position)
        }

        override fun getItemCount(): Int {
        return items.size
        }


        Result :

        enter image description here




      if you want to see the full source, just go to this link






      share|improve this answer




























        -1












        -1








        -1







        For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.





        1. The first Step you should add Viewpager in parent xml :


          activity_main.xml






          <ImageView
          android:id="@+id/left_arrow"
          android:layout_width="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_height="wrap_content"
          android:layout_centerVertical="true"
          android:layout_alignTop="@+id/view_pager"
          android:rotation="180"
          android:padding="8dp"
          android:layout_alignBottom="@id/view_pager"
          android:src="@drawable/ic_arrow"/>

          <android.support.v4.view.ViewPager
          android:layout_width="match_parent"
          android:id="@+id/view_pager"
          android:layout_toLeftOf="@id/right_arrow"
          android:layout_toRightOf="@id/left_arrow"
          android:layout_height="150dp"/>

          <com.rd.PageIndicatorView
          android:id="@+id/pageIndicatorView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/view_pager"
          app:piv_animationType="worm"
          app:piv_dynamicCount="true"
          android:layout_marginTop="10dp"
          android:layout_centerHorizontal="true"
          app:piv_interactiveAnimation="true"
          app:piv_radius="3dp"
          app:piv_unselectedColor="#999999"
          app:piv_selectedColor="#000000"
          app:piv_viewPager="@id/view_pager"
          attrs:piv_padding="8dp" />
          <ImageView
          android:id="@+id/right_arrow"
          android:padding="8dp"
          android:layout_alignTop="@+id/view_pager"
          android:layout_alignBottom="@id/view_pager"
          android:layout_alignParentRight="true"
          android:layout_width="wrap_content"
          android:layout_centerVertical="true"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_arrow"/>





        2. In this step you should create Viewpager adapter :


          pageAdapter.kt



          override fun getItem(position: Int): Fragment {
          val firstItem = ((position + 1) * 3) - 2
          val lastItem = ((position + 1) * 3)
          val itemSet = arrayListOf<String>()
          for (i in firstItem..lastItem) {
          if (i <= items.size)
          itemSet.add(items[i - 1])
          }
          return ItemFragment.newInstance(itemSet)
          }

          override fun getCount(): Int {
          return size
          }



        3. In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :


          ItemFragment



          // Creates the view controlled by the fragment
          val view = inflater.inflate(R.layout.page, container, false)
          val recycler = view.findViewById<RecyclerView>(R.id.recycler)

          // Retrieve and display the movie data from the Bundle
          val args = arguments
          recycler.layoutManager = GridLayoutManager(activity,3)
          recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)



        4. And The Last Just create RecyclerAdapter and show data to each item in list:


          ItemAdapter.kt



          override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
          }

          override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          holder?.title?.text = items.get(position)
          }

          override fun getItemCount(): Int {
          return items.size
          }


          Result :

          enter image description here




        if you want to see the full source, just go to this link






        share|improve this answer















        For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.





        1. The first Step you should add Viewpager in parent xml :


          activity_main.xml






          <ImageView
          android:id="@+id/left_arrow"
          android:layout_width="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_height="wrap_content"
          android:layout_centerVertical="true"
          android:layout_alignTop="@+id/view_pager"
          android:rotation="180"
          android:padding="8dp"
          android:layout_alignBottom="@id/view_pager"
          android:src="@drawable/ic_arrow"/>

          <android.support.v4.view.ViewPager
          android:layout_width="match_parent"
          android:id="@+id/view_pager"
          android:layout_toLeftOf="@id/right_arrow"
          android:layout_toRightOf="@id/left_arrow"
          android:layout_height="150dp"/>

          <com.rd.PageIndicatorView
          android:id="@+id/pageIndicatorView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/view_pager"
          app:piv_animationType="worm"
          app:piv_dynamicCount="true"
          android:layout_marginTop="10dp"
          android:layout_centerHorizontal="true"
          app:piv_interactiveAnimation="true"
          app:piv_radius="3dp"
          app:piv_unselectedColor="#999999"
          app:piv_selectedColor="#000000"
          app:piv_viewPager="@id/view_pager"
          attrs:piv_padding="8dp" />
          <ImageView
          android:id="@+id/right_arrow"
          android:padding="8dp"
          android:layout_alignTop="@+id/view_pager"
          android:layout_alignBottom="@id/view_pager"
          android:layout_alignParentRight="true"
          android:layout_width="wrap_content"
          android:layout_centerVertical="true"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_arrow"/>





        2. In this step you should create Viewpager adapter :


          pageAdapter.kt



          override fun getItem(position: Int): Fragment {
          val firstItem = ((position + 1) * 3) - 2
          val lastItem = ((position + 1) * 3)
          val itemSet = arrayListOf<String>()
          for (i in firstItem..lastItem) {
          if (i <= items.size)
          itemSet.add(items[i - 1])
          }
          return ItemFragment.newInstance(itemSet)
          }

          override fun getCount(): Int {
          return size
          }



        3. In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :


          ItemFragment



          // Creates the view controlled by the fragment
          val view = inflater.inflate(R.layout.page, container, false)
          val recycler = view.findViewById<RecyclerView>(R.id.recycler)

          // Retrieve and display the movie data from the Bundle
          val args = arguments
          recycler.layoutManager = GridLayoutManager(activity,3)
          recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)



        4. And The Last Just create RecyclerAdapter and show data to each item in list:


          ItemAdapter.kt



          override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
          }

          override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          holder?.title?.text = items.get(position)
          }

          override fun getItemCount(): Int {
          return items.size
          }


          Result :

          enter image description here




        if you want to see the full source, just go to this link







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 8:44

























        answered Nov 20 '18 at 23:35









        Hassan NaghibiHassan Naghibi

        395




        395
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398561%2frecyclerview-with-3-by-3-item-horizontal-scroll%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to send String Array data to Server using php in android

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Is anime1.com a legal site for watching anime?