Dynamically add views to tablerow - android

guys
I am wondering about the lenght of a table row.
In my application, views are dynamically created and added to tablelayout...and it gives no problems.
However, if the length of row is longger than the width of screen(since too many views are contained on the row), I can't see some of views on screen.
Do you know how to check it in prior to actually display the row on screen?
Thanks for your help.

You can use the tableRow attributes and change the height and width of it dynamically
TableRow tableRow = findViewById(R.id.tableRow1);
tableRow.setMinimumHeight(minHeight);
tableRow.setMinimumWidth(minWidth);
tableRow.setWeightSum(weightSum);

Related

DataGrid Android Studio horizontal vertical scroll

I am looking for solution where could dispay large data with horizontal and vetical scroll. Something like this https://www.syncfusion.com/blogs/post/new-datagrid-for-xamarinios-and-xamarinandroid.aspx. I would like to change number of columns and change the cell values.
Do you have please something like this? When it be a free i will be really happy. Thank you
You can create it by custom TableLayout. And the good news is you can add both side scrolling mechanism in TableLayout. You have to first set a TableLayout xml. For both side scrolling you have to add first ScrollView then HorizontalScrlollView then your TableLayout.
Now you you can create row and column. You can create it dynamically because you (may be) dont know how many column has required. So you have to create custom TableRow and cell and you can easily add your tableLayout .
TableRow row= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
// then create your text view and add it row. and last add row in your table layout
This is just example. You can create your own data grid library
And you can some ready mate library to show data grid in table view like your reference. :
https://github.com/evrencoskun/TableView
https://github.com/ISchwarz23/SortableTableView

TableLayout row strech/shrink

I'm trying to fit a 20x20 table into a view using a programmatically built TableLayout. The setStretchAllColumns/setShrinkAllColumns methods work perfectly for squeezing all the columns in, but I haven't found a way to get all the rows in.
Is there a corresponding method for packing the rows in?
There aren't any setStretchAllColumns/setShrinkAllColumns for rows in a TableLayout. One thing that you could try(I haven't tested it) is to give your TableLayout a weigtSum of 20(with the method setWeightSum()) and then set the weight(the layout_weight attribute from a xml layout) of 1 for each of your 20 TableRows in the TableLayout.

Loop through list of TableLayout and add each one to a LinearLayout

I have a List of TableLayout's that are each generated from data in my database. I need to loop through this list and add each TableLayout to my LinearLayout.
Below is the code I currently have, however it looks like each time the table is added, it is replacing the last one so the end result is the app displaying only the last table in the list (as far as I can tell)
container = (LinearLayout) findViewById(R.id.container);
for (int i = 0; i < listOfTables.size(); i++) {
container.addView(listOfTables.get(i), i);
}
Any ideas?
Max.
You need to play with the XML height and width attributes, in all likelihood.
Try changing the layout-height and layout-width attributes for the table layouts and the linear layout to wrap_content and see what that does :)
You might also try changing the code so it doesn't have the 2nd argument. It should add the layouts linearly.
Hope this helped!

Manage View of a Table Row at runtime

In my application i am creating and displaying a table at runtime. The table is developed in an Activity class. Everything working fine, only issue is the view of the table. There are four textviews in a row in the table. they are shown adjacently without seperation. How could i make a proper view with a definite space between textviews.
text1.setText("24/02/2011"); //TextView text
text2.setText("Andy"); //TextView text
text3.setText("3"); //TextView text
text4.setText("Repeat"); //TextView text
tableRow.addView(text1); //TableRow tableRow
tableRow.addView(text2); //TableRow tableRow
tableRow.addView(text3); //TableRow tableRow
tableRow.addView(text4); //TableRow tableRow
dueTL.addView(tableRow); //TableLayout dueTL
It display the data like : 24/02/2011Andy3Repeat
You can add weight to each TextView, also be sure that your TableView has fill_parent in its width. Also check the padding and margins of the TextViews
I hope this helps
If for some reason setting weights doesn't work for your situation, take a look at padding, paddingBottom, paddingLeft, paddingRight, and paddingTop in http://developer.android.com/reference/android/widget/TextView.html
You could either manually add a space to the strings in "setText" or you could set a right margin, if the surrounding ViewGroup supports it, on the TextViews either in XML (layout_marginRight) or via Code (LayoutParams).

Setting a semi fill_parent layout width in an Android interface

I am trying to create a table row element where the first line contains a title followed by an ImageView that should be all of the way to the right. The TextView should fill the entire width of the phone except for the ImageView at the end.
The solution depends on some details of the circumstances.
If all the rows have the same format
If all the rows have the same column layout, then set android:stretchColumns="0" on the TableLayout. This will make the first column (index 0) stretch to fill any remaining space.
If the header has a different format from the remaining rows
If you have more columns or need a different column layout for the rest of the rows, then you need to do something different. I don't believe any single item can span multiple columns.
If only the positioning is important and you don't really need to span across multiple rows, you can use the android:layout_column attribute on each of the header items. The column number is 0-based, so the first column is 0. The Eclipse layout builder doesn't seem to present this attribute, but it will handle the attribute if you type it into the xml.
If you can't fit your elements inside the same columns the rest of the table uses, then the header doesn't belong in a TableRow. As suggested in another answer, you can use a RelativeLayout instead of the TableRow. Alternately, you could move the header outside of the table.
First, use a RelativeLayout for your row. Use the typical ImageView, give it an id, and use the XML attribute android:layout_alignParentRight="true". Next, use the TextView, use android:layout_toLeftOf="#id/myid" and make sure it's width is "fill_parent".
edit: code tags

Categories

Resources