Click here to Skip to main content
12,698,012 members (25,234 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java Mobile Android
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 21-Dec-12 4:25am
halabella1.3K
Updated 21-Dec-12 4: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?
halabella 21-Dec-12 9:35am
   
It must be switched to another layout, I tested in debug mode - execution doesn't go there at all.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

http://developer.android.com/reference/android/widget/Button.html[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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)!
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100