I'm having issues understanding exactly how the RecyclerView works. So the LayoutManager positions views within the RecyclerView and determines when to use item views that are no longer visible so how many different "views" does it create. For example, if I create a card view containing an ImageView and two TextViews and have a data source of say 20 objects to display into these cards, how many cards does the RecyclerView create? Since it's "recycling" views I wouldn't think it would create 20 at once since the user might only be able to see 5 at once on screen so does that mean it creates enough to fill the screen and populates them on the fly? I'm confused.
I have an app which loads a boatload of images and displays them in a TableLayout which is inside a ScrollView. At run time I get the width of the layout parent and use that to determine how many images can go in each TableRow (all of the images are of a set size).
I'm concerned about memory issues when loading more and more images. I know ListView recycles its views but I don't know how to dynamically change number of views in each item. I am only aware of inflating XML which isn't going to change the number of views per item at run time.
So my question is what is easier - figuring out how to recycle views in my table by myself, or making a list's items change based on screen size? Just a link to a tutorial on how to do whichever is easier is good enough an answer for me.
I suggest you to use ListView with the ViewHolder approach (you can see it here: How to load the Listview "smoothly" in android).
The ListView, when scrolled, removes the views that are no more visible and gets the views that are about to become visible. This way, it's better than using a ScrollView and a TableLayout.
Can any one explain the difference between Scroll View and List View? When to use which one? And which one is more efficient?
ScrollView is used to put different or same child views or layouts and the all can be scrolled.
ListView is used to put same child view or layout as multiple items. All these items are also scrollable.
Simply ScrollView is for both homogeneous and heterogeneous collection. ListView is for only homogeneous collection.
They're completely different.
A ScrollView is simple a scrolling container you can use to scroll whatever you put inside it, which might be a list of items, or it might not.
http://developer.android.com/reference/android/widget/ScrollView.html
A ListView is very specifically designed to hold lists, where items typically look the same (or at least follow a pattern, e.g. section headings). ListView is also designed to connect to a data source of some sort, SQLite, array, content provider etc. ListView can scale to handle enormous numbers of list items.
http://developer.android.com/resources/tutorials/views/hello-listview.html
If you have data you need to show in a list, use a ListView. If you just need scrolling content, then a ScrollView is probbaly enough.
ListView:-
In ListView You can manage layout of items in xml easily that you want to display in list.
You are required to tell the adapter ho many item you want in your display list.
You can design for both homogenous as well as heterogenous views depending on your requirement by overrifing getItemViewType() method of Adapter.
In ListView items in list are created according to screen size. i.e How many items can appear on screen are created additional views(items) are created when list is scrolled at runtime. The views that are displayed once are cached when they move out of screen and when list is scrolled back to previous state the same views are displayed but this time view are not created rather they are fetched from cache.
ScrollView :-
Cache concept is not applicable with ScrollView.
All views are created at once when they come to screen and are not cached when they move out of screen while scrolling. They are present in memory(main) that may lead to memory leak because the number of objects created are not being destroyed by garbage collector since they are being referenced untill you are on same page.
Although you can create both homogenous as well as heterogenous views. If there are more items to be displayed in your list it would be tedious to manage the layout whether you are designing in xml or creating dynamically using Java code.
It is preferable to use scrollview if you have a single page that does not contain list of items e.g registration form, reservation form but that view is larger than the screen size then put ScrollView as parent view also keep in mind that ScrollView can have only one direct child layout/view.
ScrollView simply places its contents in a scrollable container, you can edit it's contents only by adding views to it.
ListView is a class that uses an adapter which handles creating the views for your data objects, you only need to edit the data, and the layout modifications are done automatically by the adapter.
ScrollView should be used when you have a screen (ex: a form with multiple fields) that do not fit into one screen on small devices, as such scrollview offers the user the possibility to scroll down.
ListView should be used when representing sets of data.
You can read about these at http://developer.android.com/guide/index.html
A ListView is backed by an Adapter, which contains a DataSource. This allows you to easily display data in rows.
A ScrollView allows you to put content inside of it, and if the content exceeds the size of the ScrollView, it will allow the user to scroll.
They both have their uses, but it depends on what you are trying to do.
Since an image worth a thousand words, here are perfect real life examples:
Listview is like the Kijiji app
Scrollview is like the EBay app
Also, see a scrollview like a billboard or a wall, where you can put bunch of different stuff on it.
And a listview is more like a result page: results are all of same nature, therefore they fit perfectly in a listview. Like a contacts list: they all share the same structure; phone number name address, etc....
I have an unusual project that I need to display large sets of questions to the user. Given the amount of questions that will be shown on the screen and accessible by the user I have opted to using a ListView. I tried a ScrollView, but it wasn't as efficient as I wanted, and lagged when dynamically adding new sets of questions.
The basic structure will be a ListView whose children are custom Views that I have created that have LinearLayouts inside that expand and collapse based on a button in each custom view. The LinearLayouts will hold the question's widgets, TextViews, Buttons, EditTexts, etc. In each collapsible view there will be at least 20 widgets. There will be many custom views in the ListView. One problem I had was scrolling of the ListView when showing that many widgets. It worked OK when the custom views were collapsed, but when a bunch were expanded it lagged the scroll.
Is there a more efficient way of displaying huge amounts of widgets than enclosing them in a ListView? I thought ListView might be my best bet because it recycles the Views.
This is a very unusual project, as the questions inside the ListView will change dramatically based on certain information entered by the user.
For having this kind of list is better to use the ExpandableListView
It have a better performance but you only draw one item expaned.
I am developing an app and am looking for some general guidance:
The app is a memory trainer, and will have a couple of different modes:
Numbers: Up to 400 digits will be displayed on the screen in a gridlike pattern
Faces: Images of faces will appear, approximately 9 to a page, also in a grid pattern
The question is: can I accomplish this with a single xml layout file, and should I use the same layout type for each (and if so, what should it be!) ? It's a large app, so consistency would be heavenly.
I would prefer a layout with flexibility, and I am leaning toward GridView right now.
Any thoughts?
A Grid view is basically like a list view where items are arranged in a static grid.
It retrieves views from the Adapters as scrolled by user.
A table layout is a layout manager and does not do scrolling if required.this means u have to put it inside a scroll view. This implies that all of the data you are displaying must be populated into the TableLayout up-front, so the ScrollView knows the total space it is to scroll in. It also does not directly give you per-"item" selection or interaction, because a TableLayout doesn't have items, it is just a layout manager.
Also Adapter -based view should be used where significant amount of data is there to be scrolled. So it seems that grid view would be more suitable in the situation u r working.