I have a design which is covering ListView as a inner view inside four views. This ListView keeps on updating every milliseconds because we are displaying live data from BLE device.
So, for that four views is it good idea to put into a RecyclerView with four rows or keep four different LinearLayouts.
Please consider this question as speed of the application point of view.
Please refer below image for better understanding.
I have a ListView with various types of elements. Those elements are retrieved from an API, so they are dynamic. One of the possible elements is a photo gallery where photos must be displayed in pairs. I'm rendering this element using a two columns GridView. In other words: one of the possible ListView elements is a GridView. I know isn't a good practise to embed one ScrollView inside another one, but it's the best approach I've found.
There’s a problem with the ListView rendering, when it reaches the GridView, it freezes because it inflates all the elements inside the GridView regardless which are really going to be shown in the UI. I mean, if the GridView contains 200 elements, it inflates all of them. I don’t know how to make the GridView respect the common pattern of Android GroupViews, just inflate the displayed elements on screen in each particular moment.
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.