I have a list CardViews, each of which has a title and an icon. Upon clicking on each item, an Activity opens with that certain card's details.
I don't think I need more than a few items (I don't think more than 10), and I'm not sure how dynamic and changing they will be.
My question is: Should I use a RecyclerView to show these items, or should I just duplicate the cards and show them inside a LinearLayout without a RecyclerView?
In terms of performance, which option is better?
Both options should be OK (I haven't tested the performance, but both run OK), although I would prefer the Linearlayout. Because the list is small, you lose most advantages of the RecyclerView (performance-wise).
If you decide to go with the LinearLayout, you could create a Compound control and reuse it for the different items so you don't have to edit every item manually if something changes.
And if you would decide to use the RecyclerView, don't forget to call setItemViewCacheSize() and set it to a reasonable amount (the count of your items), because for so few items it doesn't make sense to need to re-populate the items every time you scroll. It makes sense for bigger lists, where you can't effectively work with that many items, but for cca 10 items it seems faster if you cache them all. The next thing you should also do is call setHasFixedSize(true) on the RecyclerView. And if you don't need nested scrolling, call setNestedScrollingEnabled(false) too, otherwise the scrolling might behave a bit strange (no "fast/continued scrolling" if you swipe quickly).
Hope this helps.
Related
I am writing my self a ListView that will contain multiple types of items. I have done that using ArrayAdapter and a ListView now my issue is that I need to have some Items inside my Adapter that is gonna expand and that will have inner items of any type. Now the issue is how can I do this? I know I can use ExpandableListView but I don't need some items to be expanded. I saw this post about something similar, The person suggested to use ExpandableListView or a Custom Item, I would like to do the Custom Item but my concern is that the OP of the answer quoted this.
If the number of items is low consider using a linearlayout to look
like a listview and another linearlayout for the last item.
I'm not sure what they mean by "low" How many items can I have inside it? Would it cause lag?
so my question is what is the best way to do this? I need to put items
in a ListView that is of multiple types, and one of the types can
expand and have inner views that can again contain the same types and
so on.
Edit: Since 2 of you confused of what I want. I want to do the following inside my ArrayAdapter
Item
Item
Item
ExpandableItem {
Item
Item
Item
Item
}
Item
Item
I am trying to make some of the Items expand to have more items inside them and control the onClick of the inner items and such.
About the meaning of "low": I think it's about performance but devices today are better than devices were in 2013 when the linked post was written - maybe you'll never experience a sluggish UI with your approach. Of course this depends not only on your UI structure but also on the type of data you'll be showing (videos or just text?) and on other factors like does the device have to perform heavy work in the background or not.
RecyclerView was developed to be a "better ListView", so if performance can be an issue, then maybe it is a good choice. (The adapters for both ViewGroups can handle different View types but RecyclerView offers a better means of showing changes to single items and customizing change animations, another point in its favor)
How can I do this?
Have different View types for expandable and flat items
You can "manually" expand/ shrink a View (AFAIK your only choice when working with ListView) by using some type of animation (or the Transition framework) but you always have to...
Keep track of the expanded state of each expandable item (e.g. in the Adapter) and use them in getView() respectively onBindViewHolder().
Add another ListView like RecyclerView on clicking of any item.
I have 'profiles' activity that shows a ListView items and from there the user picks 1-5 items (max 5) and goes in another 'showcase' activity which shows these items. I'm using the cursor adapter to display the listview in both activities but obviously it displays only the chosen 5 in the 'showcase' activity and here I want to reorder them. I really don't care how will the ordering work... looking for the simplest solution out there. I don't think RecyclerView is a good idea because all the items will be visible all the time and there won't be any scrolling. Any approach will be helpful.. but at least something because i'm really stuck..! I'm having a database associated with the ListView and maybe I can put a field for order number or something..??
I was prototyping an app with a recycler view where it boiled down to basically this concept:
There is one single list, which is entirely scrollable (this bit is important).
The items in question in the recycler view are however very heterogeneous. It is not like I want to have either an image or a text, but sometimes it is a simple "list item (clickable text)", sometimes it is a row with 3 buttons, sometimes it is an icon with text, another one is a button, etc.
While similar item types have similar behaviour, the groups itself are different. They need a different manager, a different ViewHolder to process their very different button events etc.
I find it not very convenient to put everything into the recycler view's adapter with some common base class and delegate everything those different items can do to some callbacks. It feels very clunky.
Is there some better way of handling that? The advantage of the recycler view is that it scrolls well. I personally do not need any lazy creation of those items (= recycling) so I am not winning much here. The other advantage is that I do not need to handle every items creation. Which is also the downside, I need to channel it through the adapter with its getItemViewType based on position etc.
Hi everyone.
I've come up with an idea for an Android App, and I was thinking how to turn my thoughts into something working. I know how to program for Android even though I'm not that advanced as you might see, so I wanted some tips from you guys who I'm sure will be able to help.
Idea
I was thinking about an App to organize stuff, see your objects on a list and be able to add, move or remove them from the list.
Thoughts
I first thought I needed a RecyclerViewto display each item. Then I thought every item itself might be a box, and so be containing other items inside: this brought me to think of a sort of "nested" system of RecyclerViews. Before going too deep into this system I had to clarify each item should have been a Class, each of which should have had a RecyclerView assigned.
Question
I was wondering how I could make this "nested" system of RecyclerViews. I thought about making a RecyclerView an object, because I need each RecyclerView to display, function and be always the same in any screen of any item. But I don't know what the best way is.
Should I make it an object? How do I create a new RecyclerView through a button so the user can first tap an item and then, eventually, tap a button (inside the item details view for instance) to make it a box item and so create and open a RecyclerView when tapped?
P.S.
It may seem like multiple questions but it actually is only one: how to add and display a RecycerView when I tap a button inside a details screen of an item, of course automatically (have a reference to that RecyclerView).
You have to create the RecyclerView that holds your items list, let's call it rv_list, this RecyclerView has an adapter that takes each item and adapts it to an xml layout row_item.xml that you should define. Now to make an item itself display its own recyclerview you should put a recyclerview inside row_item.xml and populate it when adapting that item to rv_list inside the method onBindViewHolder.
I'd like to implement a UI experience in Android where a user can view a single item (for example, an item in my case is a collection of texts), and swipe left or right on the item to go to the previous or next item.
From my research, ListView does not implement horizontal scrolling. Potential candidates seem to be HorizontalScrollView and GridView, but I haven't seen any examples that can do this simply - only seemingly complicated libraries that need to be included.
My question is, is there a way to use ListView, HorizontalScrollView, GridView, or a combination of them to implement a horizontal scroll that shows one item at a time and snaps to the item being displayed?
The highlighted area in the picture below shows where I'm trying to implement this logic.
It looks like the best option to achieve this experience is a ViewPager, which requires the android support library.
http://developer.android.com/reference/android/support/v4/view/ViewPager.html