• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to add textviews dinamically

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic