[Logo]
Forums Register Login
how to add textviews dinamically
I need to show some data in TextViews.But data may vary.So i need to add TextViews Dynamically.Can anyone tell me how to show to do this?
below is part of my xml file.Initially i have some textviews in the file.I need to add sometextviews some times.


Find the ViewGroup you want to add the TextView to, create the TextView, and add it to the ViewGroup, and if the ViewGroup is already visible you will need to re-validate it to force it to show the new data. you should already know how to get the ViewGroup you want, and you can read the API on how to create a TextView and add it to the ViewGroup. Note, you mat also need to force the layout to happen again if there is not enough room for the new TextView and the ViewGroup was already visible.

A question you should ask yourself, though: Are you sure you want to build the layout in code? Or do you think you could make different layouts in XML and choose which one is appropriate to display depending on the data?
actually in my table there are 7 fixed columns.But the number of rows may differ.So i am unable to fixed the rows.Then i need to add rows programtically.So Steve can you help me to do this?
 
sam liyanage wrote:actually in my table there are 7 fixed columns.But the number of rows may differ.So i am unable to fixed the rows.Then i need to add rows programtically.So Steve can you help me to do this?

Have you read the API? Have you tried to code it? What is the problem you are having?
i tried with below,but it doesn't show me anything Steve.

this is my main class



this is my xml file.

I don't think you can use the normal LayoutParams for things that go in the table, because they don't know how to line up with the TableView's grid. For the TableRow you need to use TableLayout.LayoutParams and for the elements you put in the TableRow you need to use TableRow.LayoutParams.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 18, 2017 14:57:13.