Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java 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 3:25am
Edited 21-Dec-12 3:27am
v2
Comments
joshrduncan2012 at 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 at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
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