0

我在 Google Play (Punny Jokes) 上有这个笑话应用程序,要获得笑话,用户必须点击屏幕上的任意位置,然后在笑话屏幕上,他们才能阅读笑话。但是当他们想要另一个笑话时,他们必须回到主屏幕并再次按下屏幕,这往往很烦人。我正在尝试在笑话屏幕活动上设置另一个全屏按钮,因此他们不必返回。笑话在字符串中,我有在名为“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

}
}
 };
4

3 回答 3

3

next您已两次声明该字段。你在一个完全错误的地方有一个等号。

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

或者

Button next;
next = (Button) findViewById (R.id.next);
next.setOnClickListener(this);
于 2013-09-22T13:16:46.790 回答
0

那么你应该像这样修改代码

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

为什么你使用下一个值两次?

于 2013-09-22T13:23:23.977 回答
0

并且解决方案也在这个块中

//错误从这里开始

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

//错误到此结束

请按照上面的方式替换您的代码

于 2013-09-22T13:28:33.620 回答