I have 2 table layout . I want to hide the second layout and move the third layout to second position.
I'm hiding the the second layout and but don't know how to move the third layout to second position
TableLayout i=(TableLayout)findViewById(R.id.table2);
TableLayout i2=(TableLayout)findViewById(R.id.table3);
TableLayout i3=(TableLayout)findViewById(R.id.table4);
i.setVisibility(View.GONE);
i2.setVisibility(View.GONE);
i3.setVisibility(View.GONE);
TableLayout i5=(TableLayout)findViewById(R.id.table5);
i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section)
Try setting
i2.setVisibility(View.INVISIBLE);
Use view.removeView(id) of the table layout then when u want use view.addView(id)
You can do it like, as you said you are using RelativeLayout, so make a child LinearLayout with vertical orientation, then add all the table layouts you want to add.
Bow if you want to add a tableLayout at runtime at the first position, then do:
linearLayout.removeAllViews();
Then add the required TableLayout(here, i5) and after that add the remaining Layouts.
Edit: Your code:
TableLayout i=(TableLayout)findViewById(R.id.table2);
TableLayout i2=(TableLayout)findViewById(R.id.table3);
TableLayout i3=(TableLayout)findViewById(R.id.table4);
i.setVisibility(View.GONE);
i2.setVisibility(View.GONE);
i3.setVisibility(View.GONE);
TableLayout i5=(TableLayout)findViewById(R.id.table5);
i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section)
Are you going right, as i think your code should look like:
TableLayout i=(TableLayout)findViewById(R.id.table1);
TableLayout i2=(TableLayout)findViewById(R.id.table2);
TableLayout i3=(TableLayout)findViewById(R.id.table3);
i.setVisibility(View.GONE);
i2.setVisibility(View.GONE);
i3.setVisibility(View.GONE);
TableLayout i5=(TableLayout)findViewById(R.id.table5);
i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section)
I suggested this because of your comment section after i5 in your above code.
Related
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
How do you enable 2 or more columns on a LinearLayout while still preserving the capability to use addView(view, position) to add views at a given position.
Nested layouts aren't an option because in that case, each inner layout will have it's own indexes. I want to be able to use the addView method on the main layout such that the view goes to the appropriate column.
I think you should use tablelayout instead of linearlayout
I'd use 2 separate LinearLayouts, possibly within an outer LinearLayout, and have one LinearLayout be the left column, and the other be the right column. These 2 new LinearLayouts will both have equal android:layout_weight so that they have equal widths in the outer layout. You can then choose whether to add the new view to the left column or the right column by its ID.
I want to show a table row with three columns (TextView) but i want to divide the table row in three equal parts.
This is easily possible by setting a layoutWeightSum in TableRow in XML and making layout_weight=1 for all theww TextView.
But i adding the table at run time through java and not by xml.
All i know is the TableRow.LayoutParameter do not provide any thing for weightSum. How can i do this?
TableRow.LayoutParams pmRow = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
You can achieve this by following code.
TableLayout layout = //...findViewbyid
layout.setStretchAllColumns(true);
And make width 0dp to all the children (views) of TableRow like below.
<TextView
android:id="#+id/txt_no1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="hi" />
Note
Above is XML layout design, but you can create run time code also. Its just for demonstration.
I've got you covered, mate!
myTableRow.setWeightSum(float weightSum);
use pmRow.span=int value
like pmRow.span=3;
Create a LinearLayout xml (horizontal) with the three required Items ( TextViews). To add the row item at runtime, inflate the above said layout, and set text values and add it.
I want add two textview with orientation vertical(One below other) in a table row without using xml that is by programatically. Can anyone suggest me how to do this? Is there any other way than this? Already there are many textviews in a tablerow(horizontally).
Put a LinearLayout in the TableRow cell. Put the two TextView widgets in the LinearLayout. Use Java constructors to create the LinearLayout and the TextView widgets. Use addView() to add the TextView widgets to the LinearLayout.
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 >