Jump to content

Hey guys,

 

I just need a small help with my app cause I dont understand why something wont work.

 

On my main screen a have a button which leads to my second "menu":

 

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainmenu);
    final Button button = (Button) findViewById(R.id.buttonpreferences);
    button.setOnClickListener( new View.OnClickListener() {
        public void onClick (View v) {
            setContentView(R.layout.activity_references);
        }
    });

}

 

 

This works like a charm, but now on the second screen i have an image button that should take me back to my main screen.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_references);
final ImageButton button1 = (ImageButton) findViewById(R.id.back);
button.setOnClickListener( new View.OnClickListener() {
    public void onClick (View v) {
        setContentView(R.layout.activity_mainmenu);
    }
});

}

 

 

But the button is none responsive, i also tried making it  a normal button not and image one but it does the same.

I am using Android studios btw.

 

Can you please help me out dont know what i am missing :) ?? ty!

MAIN BUILD!

Link to comment
https://linustechtips.com/topic/623823-small-java-code-help/
Share on other sites

Link to post
Share on other sites

32 minutes ago, Mr_KoKa said:

You have declared button1 in the second block of code and you are setting the listener on variable named button. So, now your button that leads you to second menu is then set to get you back from there instead of the button in the second menu.

 

Ty i actually noticed that after making the post and fixed it but its not it, still doesnt work.

MAIN BUILD!

Link to comment
https://linustechtips.com/topic/623823-small-java-code-help/#findComment-8050405
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×