Dynamic grid layout in recycler view - android

I get the json with the header values as category.
I need to split those category as displayed in the image attached
Can any one suggest how to achieve this view using recyclerview
?

There is no need to create multiple RecyclerView as it can be done with a single one. You should create one RecyclerView. Inside its item's custom layout, your should add RadioButton, TextView and 'GridView' and
you should use GridView inside your list item as following
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
/>
It will have three columns as needed and height as wrap_content so that it can be expanded as needed.

I have a solution.
If don't get it then just ignore this answer.
1) First take one parent Recyclerview Which will consist of other RecyclerView as you need.
2) Create main adapter which will handle parent RecyclerView in which your sub RecyclerViews will be loaded as RecyclerView items.
3) Create adapter for sub RecyclerView which will assign these grid items.
4) Set layout of main RecyclerView as Vertical by LinearLayoutManager.VERTICAL and in sub RecyclerView layout should be a GridLayout.
5) For layout item of main parent RecyclerView should be a layout file with a simple RecyclerView in it, and for sub RecyclerViews, layout should be this item you want.
I hope you get this.
For further queries, please ask.
Happy to help.
Thank you.

Related

How to add dynamic number of sub items to android recyclerview item

I have a requirement in which there will be multiple child items to a RecycylerView Item. As per the requirement a single recycler view item can have maximum of four horizontal Childs and 2 vertical Childs at max. I have used recyclerview inside a recyclerview to achieve this by the results are not per the requirement. In short I need something like this
The results of recyclerview inside recyclerview is something like this. The items are not stretching to full length as highlighted in yellow.
How can I achieve this? I have user grid layout manager on inner recyclerview with spancount of 3 and tried with 4 as well. Converted to linearlayout manger horizontal but not able to get the desired result.
You can use GridLayoutManager for this. Just call the setSpanSizeLookup method and determine how many columns an item should take.

Horizontal recycleView inside Vertical RecycleView

I want to make playstore like layout i.e Horizontal recycleView inside Vertical RecycleView, I have a parent list like:
[{"pid":1,"name":XYX},{"pid":2,"name":ABC}]
and child list as shown below when I pass pid=1
[{"cid":1,"name":WWW,"pid":1},{"cid":2,"name":RRR,"pid":1}]
and when I pass pid=2
[{"cid":1,"name":DDD,"pid":2},{"cid":2,"name":VVV,"pid":2}]
I want to make it dynamic because parent and child list size can change.
So where should I make the api call for Child list
Any Suggestion would be helpful
onBindViewHolder of the parent adapter

ExpandableListView inside ScrollView is showing only one item

When I use ExpandableListView inside ScrollView it will show only one item,It is not showing all items and also when selected items it will shows all child items.
If your parent layout contains more items. Then you have to fix the height of listview in form of some dp instead of wrap_content/match_parent, or use NestedScrollView.

Scrolling entire layout with a ListView and another View

I know that is not a good practice put a ListView inside a ScrollView, that's why I want to figure out what kind of solution can handle this.
Look at the image below:
There's a block with some stuff on the top and there's a ListView below, and all of this scrolls with the entire layout. So, the question is:
How do I achieve this?
You should have just a ListView and set a headerView to this ListView to achieve what you want.
Use header View:
ListView below scrollview in Android
or Sticky List Headers if you want to make them stick on top of the listview:
https://github.com/emilsjolander/StickyListHeaders
or use different ViewTypes with your own Adapter implementation:
Listview: Only one list item with multiple textviews
Why do you assume the reviews shown there are in a ListView? To me they just look like a handful of custom Views stacked on top of each other, not an actual ListView.

Not scrollable listview in scroll view android

i need to make a layout that is scrollable, holds a listview that is not scrollable(full height of the content). So when i scroll the content above the listview is showed, and the full listview is displayed.
Is this possible in android?
what do you mean by ListView ( not scrollable).. will it have predefined items(count) ?
you can have a <ScrollView></ScrollView> inside of which a normal(linear/relative layout say id insidelayout1)
For single item of your ListView, create a separate xml(say item.xml) and try to inflate item.xml into insideLayout1.
Will that work for you.. or detail out your requirement...
If you want to put list view inside the scroll view than you have to fix the height of list view.
otherwise you can't scroll it properly.

Categories

Resources