Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to add textviews dinamically

 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried with below,but it doesn't show me anything Steve.

this is my main class



this is my xml file.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic