I am new to developing in Android, so below are some really basic questions, but I feel like populating a table in Android is not straightforward.
I have a list of objects and would like to add each object to a row in my TableView.
Also I would like to have a fixed header with fixed columns.
Each header cell should have the same width as all the other row cells in that same column.
Question 1: How do I add a column? By adding multiple TextViews to a TableRow and foreseeing borders myself? Isn't that done automatically?
Question 2: If I add a new TableRow dynamically to the TableLayout and add the same amount of columns as the header (aka new TextViews?), will these automatically have the same width as the header's column?
Question 3: Is there an easy how-to that would anwser my questions? I've been googling for a while now and I don't seem to find any simple tutorial.
You should use RecyclerView with GridLayoutManager
Related
I am learning android development ,I want to create dynamic table rows .I don't know how to create .I want to create two table .One should static and Another should be dynamic .
I referred in internet and i saw table layout , recycler view and I don't know which is best way to do it.Please someone guid me.
I want to create a tables like this
I have tried like this only
You cannot simply create table and rows as simple as in webpages. you have to use TableLayout,TableRow and textview(for rendering text inside of it).
create no of textviews as cell and add it to TableRow(android layout) then add the tablerow and add it to TableLayout and then add tablelayout to root layout. On dynamic insertation invalidate the view to see changes
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
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
I am using a table View in my xml. Currently all the rows look the same(shown as the first table), so I want the header to be different to the following rows, such as the 1st table in the picture
I tried to set the first row as buttons but they look weird, does anyone got a idea? thanks so much for the help
this post Android TableLayout Header row may be helpful to you
they are using Tables inside tables
OR
see my answer in this post. android create textViews in tableRows programmitcally
this question author is using fixed textviews as header in xml. here you can control the textview attributes to look them like headers
then he is trying to add the table contents via program
There is a requirement to have not-so-trivial dynamic list, each record of which consists of several columns (texts, buttons). It should look something like:
Text11 Text12 Button1 Button2
Text21 Text22 Button1 Button2
...
At first obvious way to accomplish that seemed to be TableLayout. I was expecting to have layout/styling data specified in res/layout/*.xml and to populate it with some dataset from java code (as with ListView, for which its possible to specify TextView of item in *.xml and bind it to some array using ArrayAdapter). But after playing for a while, all I found to be possible is fully populating TableLayout programatically. Still, creating TableRow by TableRow and setting layout attributes directly in java code doesn't seem elegant enough.
So the question is: am I at the right path? Is TableLayout really best View to accomplish that? Maybe it's more appropriate to extend ListView or something else to meet such requirements?
Using ListView and ArrayAdapter you can do more complicated layouts than just a TextView. You could specify a LinearLayout with 2 TextViews and 2 Buttons for each row in the List.
here's a similar question
Android: ListView elements with multiple clickable buttons
IMHO it depends on the amount of your data you need to render.
Build layout dinamically via inflate/addView is a quite simple task but is
also more slow than using a custom adapter. with a custom adapter you can
reuse the convertView parameter and then set the values more efficiently