Click here to Skip to main content
14,920,009 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn1 = (Button)findViewById(R.id.button1);
        btn1.setOnClickListener(buttonSendOnClickListener);
    }
    Button.OnClickListener buttonSendOnClickListener
            = new Button.OnClickListener(){

        @Override
        public void onClick(View arg0) {

            switch (arg0.getId()) { //execution does not go here when I click button

                case R.id.button1:
                    setContentView(R.layout.main2);
                    //do your button 1 work here
                    break;
                case R.id.cancel:
                    setContentView(R.layout.main);
                    //do your button 1 work here
                    break;
            }
        }
    };//on click;
}

Please, help.
Posted
Updated 21-Dec-12 3:27am
v2
Comments
joshrduncan2012 21-Dec-12 9:28am
   
How do you know it doesn't work? What kind of output are you getting? Can you explain how you know this?
[no name] 21-Dec-12 9:35am
   
It must be switched to another layout, I tested in debug mode - execution doesn't go there at all.

You should use a "View.OnClickListener". False reference though.

http://developer.android.com/reference/android/widget/Button.html[^]
   
Need to use android:onClick attribute to switch between layouts(Listener doesn't work in this case) Great thanks to TorstenH!
Work excellent but it can't be debaged(break point doesn't works)!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900