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?
Hi, Gulshan. Do all the activities have the same UI? If yes, you don't need to create 100 xml files.
posted 9 years ago
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.
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.