Android data binding for TableLayout - android

I am reading this manual https://developer.android.com/topic/libraries/data-binding/index.html and it is not clear for me, how to fill the TableLayout with rows if my data is kept in ObservableArrayList? All examples assume there to show a single record, but I want to show all records in the table.
Or may be it is impossible and I should use RecyclerView instead?

You might find this article helpful:
https://medium.com/google-developers/android-data-binding-list-tricks-ef3d5630555e#.c1vesyobm
It discusses how to turn lists in to Views in a ViewGroup. When you make it work for TableView, you might want to publish it here for people to use.
That said, if you have only a few Views, you can use data binding. If you're planning on having a scrolling list, you should use RecyclerView.

Related

Is it possible to sort data in a textview?

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.

Android engineering: ListView versus just a dynamic LinearLayout

When you are working with a long, big list, certainly one should use ListView because it handles cell recycling.
Notice here, for example Can i use nested linearlayouts instead of list view, for a big list? the OP is asking about ListView verses a dynamic LinearList -- the answer is "have to use a ListView, because of recycling"
Now, say you are making a short list -- imagine say a popup with only 10 or 20 items. It may even fit all on the one screen, so there's no recycling.
In fact, is there any difference between using a ListView and just using a LinearLayout, and dynamically populating the little views inside it?
It seems to me that the latter is in many cases much simpler, more elegant, and easier to work with. But I could well be missing something that seasoned Android engineers know about.
Should I just use an ordinary LinearList (populate it dynamically) for lists where recycling is not relevant? What's the usual, and why? Cheers!
{Incidentally, for popup cases, is there some better, lightweight method for "choose one from a popup-list" that I'm too silly to know about?! :) )
ListView(and other lists) supports very useful idea: splitting data and view. These parts could be changed at any time so it's important to support flexibility. And it could be solved by special mediator object: Adapter. Adapter roughly speaking says how to fill your view with particular data item.
So I'm sure that if you decide to use LinearLayout sooner or later you will implement you own Adapter.
If you used dynamic linear view then rendering the view will take more time as compare to listview. In listview we are rendering views which are visible only but if you used dynamic linear view then its problem.

Android- Contact details UI layout

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.

Need to make a table: which is better for performances?

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

Is a simple 50 item list enough to justify using a ListView?

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.

Categories

Resources