android:onClick="onClick"
从你的Button
.删除login_layout.xml
编辑
在你的下面进行以下更改 LoginActivity
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Toast; public class LoginActivity extends AppCompatActivity implements View.OnClickListener { Button loginButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_layout); loginButton=findViewById(R.id.btnLogin); loginButton.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.btnLogin: Toast.makeText(this, "Login button clicked!", Toast.LENGTH_SHORT).show(); break; default: break; } } }