0
I have an actyvity_main, containing 3 radiobuttons (each one corresponds to a layout), and a button. After the user selects the option, he clicks on the button, which makes a call to another Activity, where in it, I need to do with come with the selected layout.
public void onClick(View view) {
int checkeRadioButtonId = escolhaRadio.getCheckedRadioButtonId();
switch (checkeRadioButtonId) {
case R.id.rdb1:
Intent opcao8 = new Intent(this, Activity_Jogo.class);
setContentView(R.layout.layout_8);
startActivity(opcao8);
break;
case R.id.rdb2:
Intent opcao10 = new Intent(this, Activity_Jogo.class);
setContentView(R.layout.layout_10);
startActivity(opcao10);
break;
case R.id.rdb3:
Intent opcao12 = new Intent(this, Activity_Jogo.class);
setContentView(R.layout.layout_12);
startActivity(opcao12);
}
}
This way that I’m doing, he calls the layout and, after appearing he instantly calls the Activity, leaving only the Activity with its default layout.
You have to explain what you want better. One thing is certain
setContentView()
shall be called only once in each ActiveonCreate()
.– ramaral
Is there any way I can call just one Activity, passing which layout it should display?
– Makson Santos
There is but it becomes complicated to manage each of the Views that make up each of the past layouts. The best solution is to use different Fragments or Activities.
– ramaral