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

Changing View with xml file or programmtically

 
Gulshan Singh
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?
 
Pranav Raulkar
Ranch Hand
Posts: 73
Android Java Netbeans IDE
  • 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 Java Netbeans IDE
  • 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.
 
Bilal A. Siddiqui
Ranch Hand
Posts: 53
Android Chrome Eclipse IDE
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic