Skip to content

Instantly share code, notes, and snippets.

@JacquesInnocent
Created June 14, 2018 12:41
Show Gist options
  • Save JacquesInnocent/2d286e74fbbd652ad78e4c66d1af3010 to your computer and use it in GitHub Desktop.
Save JacquesInnocent/2d286e74fbbd652ad78e4c66d1af3010 to your computer and use it in GitHub Desktop.
Button intent to next activity.
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//Button id = buttonBack
//Next activity name = loginActivity
public class signupActivity extends AppCompatActivity {
private Button buttonBack;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
buttonBack = (Button) findViewById(R.id.buttonBack);
buttonBack.setOnClickListener(View.OnClickListener() {
@Override
public void onClick (View v){
openLogin() {
}
}
});
public void openLogin () {
Intent intent = new Intent(this, loginActivity.class);
startActivity(intent);
}
}
}
@JacquesInnocent
Copy link
Author

@Hitman23 check above.

@NicholasTurner23
Copy link

What do you want it to do? Explain what you want to do.

@JacquesInnocent
Copy link
Author

Navigating to a new activity. After hitting the buttonBack.

@JacquesInnocent
Copy link
Author

From the current activity (signupActivity) to (loginActivity)

@NicholasTurner23
Copy link

You know how to use intents?

..I see the inteNT
buttonBack.setOnClickListener(View.OnClickListener() {
@OverRide
public void onClick (View v){
openLogin();
}
});

OR

buttonBack.setOnClickListener(View.OnClickListener() {
@OverRide
public void onClick (View v){
Intent intent = new Intent(this, loginActivity.class);
startActivity(intent);
}
});

@NicholasTurner23
Copy link

buttonBack.setOnClickListener(this);

So you need an onclick method which listens for the id of the pressed button.

@JacquesInnocent
Copy link
Author

Okay I get it now.

@NicholasTurner23
Copy link

This method is a class method.
public void onClick(View v) {
if(v == findViewById(R.id.Button1)){
//do here what u wanna do.
}
else if(v == findViewById(R.id.Button2)){
//do here what u wanna do.
}
else if(v == findViewById(R.id.Button3)){
//do here what u wanna do.
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment