Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is better, listview or a linearlayout in scrollview when items are very limited?

I will have a screen in which there will be 11 images one below the other, so thus the list will only have one image per row. Now, I was confused in using a listview with custom adapter or a linearlayout contained by scrollview? What would be better?

like image 507
Sunil Sharma Avatar asked Mar 17 '12 16:03

Sunil Sharma


People also ask

What is the difference between ListView and ScrollView?

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. 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).

How many views can you use within a ScrollView?

ScrollView is a subclass of FrameLayout , which means that you can place only one View as a child within it; that child contains the entire contents to scroll.

Why do we use ListView?

Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list. The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.

Is a ListView scrollable?

Is ListView scrollable by default? scrollable Boolean|String (default: false) If set to true the listview will display a scrollbar when the content exceeds the listview height value. By default scrolling is disabled. It could be also set to endless in order to enable the endless scrolling functionality.


2 Answers

The benefit of a listview is that all the items are not all created in the memory. So what happens is that if the number of visible items in your list are 10, then there will be 11 items created and as you scroll the ones which go out of view are deleted and the ones that come in view are created. This is handled by the listview.

In your case, this will not happen. All 11 items will be in the memory. No matter whether they are in view or not. So I guess it depends upon ure memory handling. Other than u shouldnt have any issues as they are static. OnClick() can be done in the imageview itself. So u r good to go :)

like image 127
Shubhayu Avatar answered Nov 16 '22 02:11

Shubhayu


Base on your requirement, a scrollview would be enough.

Unless:

  1. You foresee a future enhancement on each row.
  2. You need to update the content frequently. Or you need to sort their order in run time.
like image 26
Calvin Avatar answered Nov 16 '22 03:11

Calvin