简体   繁体   English

我的OnClickListener有什么问题?

[英]What's wrong with my OnClickListener?

I have this jokes app on Google Play (Punny Jokes) and to get a joke, the user must tap anywhere on the screen, then on the joke screen, they get to read the joke. 我在Google Play上有这个笑话应用程序(“ Punny Jokes”),要获得笑话,用户必须在屏幕上的任意位置点按,然后在笑话屏幕上阅读笑话。 But when they want another joke, they must go back to the main screen and press the screen again, which tends be annoying. 但是当他们想再开个玩笑时,他们必须回到主屏幕并再次按下屏幕,这很烦人。 I'm trying to set up another full-screen button on the joke screen activity, so they don't have to go back. 我正在尝试在笑话屏幕活动上设置另一个全屏按钮,因此他们不必回头。 The jokes are in strings in I have code that selects a random random string in a class called "StartingPoint". 笑话在字符串中,我有在“ StartingPoint”类中选择随机随机字符串的代码。 Thanks so much! 非常感谢!

 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

}
}
 };

You have declared the field next twice. 声明该领域next的两倍。 And you had an equal sign in a completely wrong place. 而且您在完全错误的位置有一个等号。

Button next =  (Button) findViewById (R.id.next);
next.setOnClickListener(this);

or 要么

Button next;
next = (Button) findViewById (R.id.next);
next.setOnClickListener(this);

Well you should modify code like this 好吧,你应该像这样修改代码

Button next = (Button) findViewById (R.id.next);

and why do you use next value twice?? 为什么要使用两次下一个值?

and solution is also in this block 解决方案也在这个区块中

//ERROR BEGINS HERE //错误从这里开始

Button next;
next = (Button) findViewById(R.id.next);
next.setOnClickListener(this);

//ERROR ENDS HERE //错误在这里结束

do replace your code as above 确实按上述方式替换您的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM