0
Good people, I intend to "call" a layout randomly, the problem is to call it, I thought to store all layouts in an array and based on the randomly generated numbers call the layout at that position of the array, I thought to do so:
String listalayouts[] = new String[100];
listalayouts[0]="layout1.xml";
botao.setOnClickListener(new View.OnClickListener() {
String x="R.layout."+listalayouts[0];
public void onClick(View v) {
setContentView(x);
}
});
This does not work because x is not View type and can not cast String to view. Someone has a solution?
Thanks in advance for any help.
Switch between layouts with
setContentView()
is not a good idea, will bring many problems. Note that the methodfindViewById()
is directly connected with the layout indicated withsetContentView()
. I suggest you use Fragments.– ramaral