Skip to content Skip to sidebar Skip to footer

Android Eclipse How To Start A New Activity On Button Click

I am trying to make it so that when the user presses a button on the default activity, it opens a new activity. Here's what I've got. The code for the button: android:onClick='open

Solution 1:

You can do workaround like :

Define an Id for your button in xml layout

 <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button Text"
  />

Now in your Activity Class

publicclassMyActivityextendsActivityimplementsView.OnClickListener{



   @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);
    finalButtonbutton=(Button) findVieById(R.id.button);
    button.setOnClickListener(this);

   }

   @OverrideprotectedvoidonClick(View view) {

     switch(v.getId){
       case R.id.button :
          Intentintent=newIntent(this , MainMenuPassed.class);
          startActivity(intent);
       break;

     }
  }

 }

Post a Comment for "Android Eclipse How To Start A New Activity On Button Click"