Showing tabular data in Android - android

I need to show data from a web service with a limited amount of rows and with different number of columns (2-5 according to the ws call).
I don't know what kind of view is better to use: is it better to use a ListView with a dynamic layout using LayoutInflater or should i use a TableLayout as if it was a html page?

You can either go with Gridlayout that would be with more ease or go with TableLayout.
Using a TableLayout provide more structured and user specific look then ListView, you can make modification as per your need. like adding separators with rows, images ot arrows on the different TableRows. so best will be either Girdview or TableLayout.

Related

How to display a scrolling table inside a activity?

I'm quite new in Android programming so I want to ask what is the best way to display data in a table full with rows and columns. Also it should be able to be scrolled down to view more rows.
Here is a simple paint drawing of the way I imagine my data_activity.xml
In each column and row I will show a different number (maybe string).
Just want some guidance about this maybe a tutorial or code if existing.
You can use a ScrollView. And place inside it a TableLayout. This will allow the TableLayout to be scrolled.
Check this example of TableLayout: http://www.mkyong.com/android/android-tablelayout-example/
TableLayout doc: http://developer.android.com/reference/android/widget/TableLayout.html

How can I make the content of listview be horizontally arrange?

What should I use or do in the listview to make its content horizontally arrange? What I'm trying to do with listview is like a normal table table with header, each row is the information about the employee.I will populate the listview with the data from the database but I don't know how to make it that way that all the information of an employee should be in a row. Is it possible?
try to use 2 webview, one for the header and the other one is for the details,just concatenate the details for each employee. That works for me!
I recently wanted to create a horizontal ListView in Android. However, there was no obvious way to implement this. I ended up using a Gallery instead.
Note that the Gallery is deprecated in API level 16. The documentation points to a couple of other widgets that offer horizontal scrolling features.

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

Does Android have a Table like Adapter for ListView

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

Link array of ImagesViews to TableLayout

Does anyone know, if you have an array of ImageViews[n][n], how to connect the array to a TableLayout? Furthermore, after it's displayed in the tableLayout, is there a way to tap the images in the table layout and swap places with the adjacent tile with a specific label?
Thanks!
You will just need to construct your TableLayout manually using addView().
You might want to check out GridView which provides an easy way to "link" data using Adapters.
Edit GridView may not work for you because it doesn't specify the number of items per row.
You might also think about making a custom View and rendering your images to a Canvas using the graphics calls in your onDraw() method.

Categories

Resources