In my app I download from the net some data I need to arrange in a table way.
I already know dimensions: about 26 rows and 6 columns, anyway data can change across subsequent calls so I have to create this table in a dynamic way.
As it is a table I though using a TableLayout (never used before), on the other hand I could simply use a list view, using for the single item a 6 elements linear layout with horizontal orientation.
ListView intrigues me because it is an adapter view (I think I'll store this data in a sqllite db, later) so populating it is quite simple and straightforward, anyway I don't know if it is the best for my problem.
What is your opinion?TableLayout, ListView or other?
When it comes to performance, I think you should use ListView because ListView support Recycling of view and you can check this and this post for more detail regarding Recycling of view.
Hope it helps :)
A ListView is a collection of layouts that are automatically displayed one below the other. The developer adds new items through a piece of code in the Activity. An example is the address book where you have lots of contacts one after the other.
A TableView on the other hand is defined in the layout file and does not only need to contain elements below or above each other but can also arrange elements on the left or on the right. A TableView is exactly what it says: A table with rows and columns.
here's a similar question that might answer what you want to know
Related
I am using 'Codeofaninja' .
android table scroll code
He generates data. I replaced that with an sqlite database. It works well but...
I need to sort and the displays are textviews with tablerows.
Should I use listviews instead of the textviews/tablerows?
I have seen examples of data being sorted in a collection. I have my data in lists already but I have read that textviews have performance problems.
If the answer is listviews then I have to redesign the views which I am trying to not do. But if technology says I must then so be it.
So I have come up with 2 options:
1:textview gets repopulated with list after any data actions.
2:listview is where data is manipulated then stored back to db. Then I need to put a listview in the relativelayout view?
I have tried deleting the tablerows from the textview and reading data back in but this proves slow.
I searched on textviews and listviews and have seen many examples but it is still not clear as to what method is the preferred.
Thank you for input.
The idea is that the sorting is independent of the view. You sort the data in the collection (list, array, etc.) first, then use the ListAdapter (or ArrayAdapter, .etc) to populate the view.
From what you described, it seems the textviews are re-created every time, i.e, if you have 10 rows, each row has 3 textviews, did you create 30 textviews? In that case, sure it has performance problem. Try reading up on ViewHolder for ListView
Android Viewholder implementation
It is superior to use the idea of loading some data at a time. Both Android ListView and RecyclerView virtually loads data when required, and removes data when they are no longer needed.
One good tutorial about ListView # Populating a ListView With Data. Tell us what you think of it.
The only drawback for these GUI classes is when you only have small amount of data to show, which is not likely, from your post.
I'm building a contacts app and wanted to know what the best way of building something like the image below(Jessica is not too shabby...) in terms of using a list view, scrollview, etc.
Ideally, all of my data is in the sql database so a cursor adapter wouldn't be an issue. Is it better to have a listview with separators, or a scrollview where you add views. Since all contacts won't have exactly the same information, what can we do to make that? Any ideas would be greatly appreciated.
If you plan to have interactive elements inside of the items (e.g. the message button in the screenshot above) I'd recommend a ScrollView. Actually, since you probably don't have that many items I would again recommend a ScrollView. Then it's justa matter of having a set of layouts that you dynamically add depending on the information you have for the contact.
What would be better for presenting a results table within an Android application where all the columns and rows have uniform size. A table view, or a list view with an custom list view adapter?
What kind of data? How much data?
A list view is a far more complicated view, but it allows you to show datasets that are infinitely large (millions and millions is ok). A table view is much simpler, but if you try to use one to display even a moderate number of rows you will start to run into memory issues, depending on how complex the data in each row is.
every time I start to think TableView and start putting together a layout, I realize it just doesn't feel like I want it to, and that ListView with horizontal LinearLayouts is the way to go.
plus, putting together a custom adapter based on BaseAdapter is really straightforward, nothing anyone should be put off by
In the Google I/O 2010 talk about ListView they say you might not need to use a ListView with a bounded and reasonable number of rows. They state if you are dealing with a reasonable number of rows it is possible to just lay them out in a ScrollView.
I'm curious what people find "reasonble length" means in practice.
Would a list of 50 items with each row's views just having a few strings be reasonable to layout without using a ListView? How about 12?
I'm used to using UITableViews on iPhone for most UI so I'm inclined to use ListViews on Android but I also want to be aware it might be overkill for some scenarios and I have a really limited understanding of perf on android presently.
ListView is really the best option for anything over 3 items, it is a good option for even 2 or 3 items. If not you'll end up writing a bunch of code that converts indexes to individual variables instead of arrays, database rows, or other data structure.
It's not only about the number of items but also about whether or not your data collection will be dynamically updated. If you know you will never update the list while it's on screen and it doesn't have many items then a LinearLayout will do just fine.
In the Google I/O 2010 talk about ListView they say you might not need to use a ListView with a bounded and reasonable number of rows. They state if you are dealing with a reasonable number of rows it is possible to just lay them out in a ScrollView.
Hmmm, I can understand the logic up to a point but in reality using a ListActivity, for example, as your base class makes things very simple. OK, if you have a static list of only a dozen or so lines of text (one for each list 'item') then using a ScrollView containing TextViews would be an alternative but in reality using the adapter approach to ListViews is a lot more flexible in my opinion.
Would a list of 50 items with each row's views just having a few strings be reasonable to layout without using a ListView? How about 12?
No, if each list item has a few strings to be laid out then custom list item layouts together with a ListView and a custom adapter are basically a must.
I'm using a ListView to show a list of items. These items are in a table format with columns and rows. Is there a table like adapter to make sure all the columns and rows line up? I know this brings in the complexity of how large each column should be, what to do with cut off text, and other things. I'm just curious if there is currently and adapter hiding somewhere for this task. Or maybe even another control?
The point of using ListView is to be able to scale to larger data sets by not having to create and layout views for all of the items up-front. Because of this, your request fundamentally conflicts with how ListView works -- ListView simply doesn't know how all of its items will layout, so there is no way for it to automatically make sure they align in some way.
You can ensure they align yourself just by writing the item layout appropriately. For example, very often in the UI you will have an icon followed by a label. If you ensure the icon is a specific size, then all of the list items will align. If you are dealing with elements that are more dynamic like text, you could do the same thing by enforcing up-front a specific width for those elements.
If you really want to have the UI compute the element sizes dynamically and align all of the rows based on them, that is what TableLayout does. It can do this because it always has all elements there to layout together. If you want to allow scrolling in it, you can wrap that in a ScrollView like another poster suggested. Just be aware that this approach will quickly fall apart as your number of rows increases significantly.
I was able to make TableLayout to behave like ListView (at least visually). Here is my answer.
There is GridView for that, but afaik it doesn't work with columns and rows. Luckily you seem to have been expecting some complexity :)
You can use a ListView or a ListFragment and populate items using each time a single TableRow inside a TableLayout (maybe using android:stretchColumns="0")
you'll have a TableLayout per line, so it's probably inefficient but it does what you are trying to do