Skip to content

Instantly share code, notes, and snippets.

@SIRHAMY
Created November 19, 2013 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SIRHAMY/7551444 to your computer and use it in GitHub Desktop.
Save SIRHAMY/7551444 to your computer and use it in GitHub Desktop.
Example Java code demoing how to give a button the functionality to switch between activities.
public class ExampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Tells Android which XML file holds this class' information
setContentView(R.layout.ExampleActivityXMLFile);
//Sets up the chosen button
Button demo = (Button) findViewById(R.id.exampleButton);
demo.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v){
//ExampleActivity is the Activity we're in, TargetActivity is the Activity we'd like to show
startActivity(new Intent(ExampleActivity.this, TargetActivity.class));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment