我在 Google Play 上有这个笑话应用程序(双关语笑话),要获取笑话,用户必须点击屏幕上的任意位置,然后在笑话屏幕上,他们可以阅读该笑话。但当他们想要另一个笑话时,他们必须返回主屏幕并再次按下屏幕,这往往很烦人。我正在尝试在笑话屏幕 Activity 上设置另一个全屏按钮,这样他们就不必返回。这些笑话位于字符串中,我有代码在名为“StartingPoint”的类中选择随机字符串。非常感谢!
public class DisplayMessageActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
**//ERROR BEGINS HERE**
Button next;
Button next = (Button) = findViewById (R.id.next);
next.setOnClickListener(this);
**//ERROR ENDS HERE**
initTypeface1();
}
@Override
public void onClick(final View v) {
switch(v.getId()){
case R.id.next:
IntentHandler.switchActivity(DisplayMessageActivity.this,
StartingPoint.class, false);
break;
// TODO Auto-generated method stub
}
}
};
最佳答案
您已声明字段 next
两次。而且你在完全错误的地方有一个等号。
Button next = (Button) findViewById (R.id.next);
next.setOnClickListener(this);
或
Button next;
next = (Button) findViewById (R.id.next);
next.setOnClickListener(this);
关于java - 我的 OnClickListener 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944213/