Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Changing View with xml file or programmtically

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application there is an activity which only contains textviews and images and there are back and forward buttons, so the user can switch between each screen using these buttons and the android return key changes the screen to the last activity. Now for each different page that the user can change to in this activity should I make a new xml layout? If I take this approach there will be atleast 100 xml layouts... Instead should I programmatically implement the view or is there a better option?
 
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Gulshan. Do all the activities have the same UI? If yes, you don't need to create 100 xml files.
 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pranav Raulkar wrote:Hi, Gulshan. Do all the activities have the same UI? If yes, you don't need to create 100 xml files.


They're similar. For example, one may contain one text view and one image, while the other will contain 2 text views and 2 images. So if the best practice is to do it programmatically, I could put 3 blank text views and 3 blank images and only fill in the ones I needed programmatically. Anyway, if I do implement the 100 xml files, which actually won't be anymore work than doing it programmatically as I would have to type out the strings and image paths anyway, the application will be a few megabytes, which isn't good but I guess it will work.

Thanks.
 
Pranav Raulkar
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having a 100 XML files is't a good design. Yes, the best way to go is prepare your XML once containing all the textviews and imageviews you need and populate the ones you need while hiding the other's.
 
Ranch Hand
Posts: 53
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gulshan

Just have a look http://www.handsomeandroid.blogspot.com/ there is a post regarding dynamic android layout.

This might be of help to you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic