package com.thenewboston.jordy;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Startingpoint extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startingpoint);
}
int counter;
Button add, sub;
TextView display;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.startingpoint, menu);
return true;
counter = 0;
add = (Button) findViewById(R.id.BAdd);
sub = (Button) findViewById(R.id.Bsub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is " + counter);
}
});
}
}
你好,我刚刚开始学习使用 eclips 制作 android 应用程序的教程。现在我在“counter = 0”行得到这个错误无法访问的代码,我认为它必须对“return true”行做一些事情,因为当我删除错误消失但随后我得到其他错误:s,确实有人知道这里有什么问题吗?
提前致谢