I want to change the content on a button change, but it never works.
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.blahdyblah);
}
});
So that’s the code, but whenever I want to change setContentView(), it doesn’t change, it just clicks and does nothing. If anyone could help me in this task…
I’ve also tried putting the setContentView in another function… That still doesn’t work.
I’m guessing you want your screen to switch to another layout when the button is clicked. Try the following. First of all, make an activity called “blahdyblah” instead of just an xml file(So you should have two activities, your main activity which has the button with the onClickListener, and a separate activity called “blahdyblah”). After you’ve done that, try this:
In the code, replace “MainActivity” with the name of the class in which you are writing this onClickListener.
Set the blahdyblah.java file’s content view to
R.layout.blahdyblahI’m pretty sure that should do what you’re looking for.
blahdyblah.java