RecyclerView with 3 by 3 item Horizontal scroll











up vote
0
down vote

favorite












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 at 18:04










  • Yes which is best option to use or any other components i can use for this situation
    – Jagan
    Nov 20 at 19:38















up vote
0
down vote

favorite












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 at 18:04










  • Yes which is best option to use or any other components i can use for this situation
    – Jagan
    Nov 20 at 19:38













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 at 17:38









Jagan

1,5421432




1,5421432












  • Basically, you're asking for opinions on which component to use in this situation?
    – Shark
    Nov 20 at 18:04










  • Yes which is best option to use or any other components i can use for this situation
    – Jagan
    Nov 20 at 19:38


















  • Basically, you're asking for opinions on which component to use in this situation?
    – Shark
    Nov 20 at 18:04










  • Yes which is best option to use or any other components i can use for this situation
    – Jagan
    Nov 20 at 19:38
















Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04




Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04












Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38




Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38












1 Answer
1






active

oldest

votes

















up vote
-1
down vote













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




    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Comintern
    2 days ago











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',
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








up vote
-1
down vote













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




    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Comintern
    2 days ago















up vote
-1
down vote













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




    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Comintern
    2 days ago













up vote
-1
down vote










up vote
-1
down vote









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 2 days ago

























answered Nov 20 at 23:35









Hassan Naghibi

295




295








  • 1




    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Comintern
    2 days ago














  • 1




    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Comintern
    2 days ago








1




1




While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago




While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago


















 

draft saved


draft discarded



















































 


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

Sphinx de Gizeh

Dijon

Guerrita