0

I have a MainActivity.java file with a single layout. I created a new layout that is simply called layout2, and want to call it somehow in the MainActivity.java file, to switch between the 2 layouts with a btn click, but without any .java class file (like in Activities: .java file goes with his own single layout).

For short:
An Activity open (just) a new layout file.

Thanks for any answers.

ImageButton ibtt;
ImageButton ib = (ImageButton)findViewById(R.id.ibtt);
ib.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      MainActivity.setContentView(R.layout.secondlayout);
    }
});
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Katona Tamas
  • 227
  • 1
  • 2
  • 6

1 Answers1

1

Not entirely sure what you are trying to do but a Viewflipper sounds something you might like. Define a viewflipper with as many children as you want in the xml. The children can be separate layouts each. Use the<include> tag. Plenty of examples with viewflipper on StackOverflow. I prefer using a statekeeper along with one always.

EDIT: Here's an example How to use view flipper with three layouts?

costa
  • 19
  • 3
  • This answer would be perfect if it linked to the documentation for ViewFlipper and/or some other SO questions about ViewFlipper. – emerssso Mar 21 '18 at 21:44