Jan 11 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned off guest access |
Mark M. | turned on guest access |
Aman | has entered the room |
Aman |
Hello Mark
|
Mark M. |
hello, Aman!
|
Mark M. |
how can I help you today?
|
Aman |
First time here, nice to meet you!
|
Mark M. |
nice to meet you too!
|
Aman |
Here's my question:
|
Aman |
View paste
(9 more lines)
|
Mark M. |
OK
|
Aman |
View paste
|
Aman |
View paste
|
Jan 11 | 4:00 PM |
Mark M. |
have two different layouts for the "pages" in the RecyclerView
|
Mark M. |
one layout has two items
|
Mark M. |
the other layout has one item
|
Mark M. |
in other words, the ViewHolder and Adapter are adapting pages, not items
|
Mark M. |
you use the two-item layout for the first two pages, and the one-item layout for the other two pages
|
Aman |
i thought about that but I need each item to really be separate because each will have it's own onclicklisteners
|
Mark M. |
have two different ViewHolder classes, one for one-item pages and one for two-item pages
|
Mark M. |
where they handle the correct number of event listeners per page
|
Mark M. |
if you ignore the items for the moment, your description is for a four-page UI
|
Mark M. |
and so the simplest way to implement that is to have a four-page UI, whether you use RecyclerView or ViewPager
|
Mark M. |
it just so happens that on two of those pages, you want to show two items apiece
|
Mark M. |
but that's an implementation detail of the *page*, not the overall structure for showing the pages
|
Aman |
i see
|
Mark M. |
it is fairly common to have pages with significantly different results
|
Jan 11 | 4:05 PM |
Mark M. |
for example, the stock dialer on a Nexus 5X has four pages (tabs), with favorites in a grid, call history in a list with headers, contacts as a list, and voicemail (I think as a list)
|
Mark M. |
that activity will have either four separate ViewHolder classes or four separate fragments, depending on whether it is using RecyclerView or ViewPager
|
Aman |
yes, i'm looking at it now
|
Aman |
And can you give me your thoughts on whether a RecyclerView is a good choice here? Is there something else that would fit better like the ViewPager u mention.
|
Mark M. |
on the whole, I am tending to use RecyclerView more for this scenario
|
Mark M. |
there is nothing wrong with ViewPager, and if it simplifies your life if your pages are fragments, ViewPager is the better solution
|
Aman |
ok
|
Aman |
i've looked up using a listview horizontally but found different solutions with their own problems, do you recommend that?
|
Aman |
would you use a listview for horizontal scrolling?
|
Mark M. |
no
|
Aman |
ok
|
Mark M. |
in fact, AFAIK, that is not strictly possible
|
Mark M. |
there are horizontal list libraries, but AFAIK they are not using ListView as a base
|
Aman |
i see
|
Mark M. |
but, I haven't paid them much attention since RecyclerView was released
|
Jan 11 | 4:10 PM |
Aman |
right ok
|
Aman |
what about using a gridview for horizontal scrolling?
|
Mark M. |
I do not think that GridView offers horizontal scrolling
|
Mark M. |
the only horizontal scrolling option we had in the early days was Gallery, which is long since deprecated
|
Mark M. |
then we had ViewPager
|
Aman |
i see
|
Mark M. |
and HorizontalScrollView was added around the same time
|
Mark M. |
now, we have RecyclerView
|
Aman |
ok
|
Mark M. |
there are third party libraries with other options, and you are welcome to explore them
|
Mark M. |
for me, RecyclerView is sufficient for most of my needs
|
Aman |
ok, going back to my use case, i want to give the user a hint that there are more items to the right to scroll to, i was thinking to show a little bit of the title
|
Aman |
would you say the title should be in the viewholder?
|
Mark M. |
I cannot really answer that
|
Aman |
the title should scroll along with the items and come to the middle
|
Jan 11 | 4:15 PM |
Mark M. |
then the title is part of the layout that you are using for the pages
|
Mark M. |
however, that does not really fit your "show a little bit of the title" approach
|
Mark M. |
as the that extra title is in the wrong place, presumably
|
Aman |
would i be able to have it scroll at a different rate?
|
Aman |
right
|
Mark M. |
possibly, but I have no idea how
|
Aman |
i think that's why i need it outside the recyclerview
|
Mark M. |
I would consider adapting one of Jake Wharton's old ViewPagerIndicators for use with RecyclerView
|
Mark M. |
such as the one that shows dots
|
Aman |
is that only for ViewPagers?
|
Mark M. |
yes, though presumably it could be adapted, if nobody else has adapted it already
|
Mark M. | |
Mark M. |
that's a standalone dot indicator library
|
Jan 11 | 4:20 PM |
Aman |
yes, nice
|
Aman |
what do u think about this:
|
Aman | |
Mark M. |
that seems to be a similar concept, more closely coupled with RecyclerView
|
Mark M. |
I'm impressed that item decorators can pull that off
|
Aman |
OK, I really appreciate all your help, thanks much!
|
Jan 11 | 4:25 PM |
Mark M. |
you're welcome!
|
Jan 11 | 5:00 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Tuesday in the same time slot (4pm US Eastern)
|
Mark M. |
have a pleasant day!
|
Aman | has left the room |
Mark M. | turned off guest access |