[Solved] Is it possible to store else-if statements in a XML file and call it from activity?


Why don’t you create the URL with the pos value directly ? You’ll avoid your if/else statements.

It would be something like that

int pos = getIntent().getIntExtra("key",0);
String url = "file:///android_asset/"+pos+".html"
web.loadUrl(url);

Ok it seems like you have different file names. So what you can do is store those in a Map.

Map<Integer, String> map = new HashMap<>();
map.put(0,"games");
map.put(1,"softwares");
map.put(2, "music");
/*****
 And so on
*****/
int pos = getIntent().getIntExtra("key",0);
String url = "file:///android_asset/"+map.get(pos)+".html"
web.loadUrl(url);

5

solved Is it possible to store else-if statements in a XML file and call it from activity?