Sunday, April 14, 2013

[android help] Using If and else to change to change layout file @ runtime

android - Using If and else to change to change layout file @ runtime - Stack Overflow




















I am currently working on a project that i am trying to add an icon making competition and the winner will receive a special app plugin that only the contest winner will get and i would like my app to check if the package(special app plugin) exists on the users device and if it does i would like the app to display an alternate display on run-time.Would i use "if" and "else" statements to achieve this and if so how would i go about this andThanks in advanced.


Note:I have successfully made the app load a different layout depending on the android version so i have a little bit of an idea but need some help.





























you can change your xml file according to your requirement in onCreate()..


as i did in my code, for the different density i used different xml file.



if (metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM) {
setContentView(R.layout.activity_main);
} else if (metrics.densityDpi == DisplayMetrics.DENSITY_LOW) {
setContentView(R.layout.activity_main_small);
} else {
setContentView(R.layout.activity_main_large);
}



















default







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...