Can we create tables with borders dynamically in Android - android

Iam trying to create a table with borders using TableLayout. If I add static rows in xml file i am able to see the borders. But the problem arises if I try to add some dynamic rows. Data for the table comes dynamically. Can anyone help in solving this problem. If possible please provide the source code(.java file and .xml file).

You can create a rectangle image to use as a background for the row. TableRow extends View, so this should work (untested).
TableRow row = new TableRow (this);
row.setBackgroundResource (android.R.drawable.edit_text);
// rest of your code
If it doesn't work, the (tested) solution is to add a color background to the table and padding to the row.

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

Android: Dynamically adding images at right to dynamic table rows

I need to add the imageview at the right side of table row that is generated dynamically..
I have added imageviews to table rows.. How to add images at right i.e. set gravity to right.
Can anyone help me over this?
Thanks
You have to create a XML file for table row and Using LayoutInflater you can get a view from that XML file.
You have to study about Layout Inflater

Android dynamically give space between tablerows

I am implementing a table layout and adding table rows to it dynamically. I want give space between these rows. may I know how to do it. I am also adding a textView to the tableRow. I am declaring the table layout in the xml file. I tried giving padding inside the table row. But that seems to work within the tableRows and not between tableRows. please help.
You need to set the top or bottom margin of rows.
Here is an example: Programmatically set margin for TableRow
To set the margin between rows in a table layout you need to use the following XML
<Tablelayout> android:stretchColumns="*" </Tablelayout >

android tablerow and columns in code

I'm trying to create a TableLayout with dynamically added rows and columns (from an array of obbjects). Since it's dynamic must I code(?)
All the examples I can find is doing it using xml layouts. The only ones out there that does it in code only adds a single view, like a button, which makes me believe its not doable, and I need two columns at least, where one of the will contain a view with an image and text.
Try to create table and row doing something like this
TableLayout t=new TableLayout(this);
TableRow tr=new TableRow(this);
and add row with table by
t.addView(tr);
similarly you can add other view (text, image view etc.) by using addView() function

Dynamically add views to tablerow

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);

Categories

Resources