setcontview(R.layout.blah) - can i define 'blah' on the fly?
开发者_开发问答Hopefully this is easy to do, I've tried searching for it with no luck, my apologies if it was previously answered.
I want to be able to build 'blah' in setcontentview(R.layout.blah) as shown below in my code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.options_sounds);
Where options_sounds will be defined by a user selected spinner. I'd like to save it as a string and then read it into the setcontentview line somehow. All the blah.xml files will have been previously built and ready to go, I just want the user to tell me which one he/she wants.
Thank you for your time. -c
You could use a switch statement and load the user's selection, since the layouts are already built and "ready to go".
switch(layout_selection) {
case 1:
setContentView(R.layout.layout1);
break;
case 2:
setContentView(R.layout.layout2);
break;
}
精彩评论