我正在尝试两个使用两个按钮和点击监听器启动两个不同的活动我收到以下错误此行的多个标记 - 语法错误,插入“}”以完成 ClassBody - 语法错误,插入“;” 完成 FieldDeclaration
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.safaricom);
Button button1 = (Button)findViewById(R.id.button1);
Button button2 = (Button)findViewById(R.id.button2);
button1.setOnClickListener(buttonClickListener);
button2.setOnClickListener(buttonClickListener);
}
private OnClickListener buttonClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
Intent intent = new Intent(this, Second.class);
this.startActivity(intent);
break;
case R.id.button2:
Intent intent = new Intent(this, SignUp.class);
this.startActivity(intent);
break;
}
}
}