Hi guys I am having trouble using a button on android studio. Currently, when I click on the button there is no response at all to the click. I am using onClickListener() and it doesn’t work so I tried to use the onClick method in XML and write your own function but that just leads to the crash of my app. Please let me know if there are any problems with my code and if you know what the problem is thanks.
XML FILE:
<androidx.appcompat.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:background="#fff"
android:elevation="0dp"
android:text="NEW USER? SIGN UP"
android:textColor="#000"
android:id="@+id/signup_btn" />
Login.class:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button button = (Button) findViewById(R.id.signup_btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Login.this, SignUp.class);
startActivity(i);
}
});
}
2
Answers
Try change your code like this :
Change this line:
To this:
And make sure both activities (SignUp and Login) are declared in the manifest.