The moose likes Android and the fly likes Changing View with xml file or programmtically Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "Changing View with xml file or programmtically" Watch "Changing View with xml file or programmtically" New topic
Author

Changing View with xml file or programmtically

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
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

Joined: Apr 20, 2011
Posts: 73

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

Joined: Apr 22, 2009
Posts: 41
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

Joined: Apr 20, 2011
Posts: 73

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

Joined: Sep 14, 2008
Posts: 53

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.


Cheers!!! Bilal
Handsome Android||@bilal_speed||LinkedIn
 
 
subject: Changing View with xml file or programmtically
 
Threads others viewed
Extracting a parameter from c:out value
Is there an easy way to make UIs?
MVC -2+ views for 1 controller??
How to pass data between active's
Adding a Button to a view created from XML
developer file tools