Issue
as follows:
Button btnSubmit = findViewById(R.id.btn_login_submit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_login_submit:
Toast.makeText(LoginActivity.this, "click", Toast.LENGTH_SHORT).show();
break;
}
}
});
Button btnSubmit = findViewById(R.id.btn_login_submit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(LoginActivity.this, "click", Toast.LENGTH_SHORT).show();
}
});
They both worked equally well. Can the switch
be omitted?
The btnSubmit
has been findViewById
. Is switch getId
repeated?
Solution
Yes you can remove switch case it work same because R.id.btn_login_submit is same
But my suggestion is use view binding instead of findViewById
Answered By - SAVAN JADAV
Answer Checked By - Senaida (JavaFixing Volunteer)