构建一个小型水龙头计数器应用程序。我希望操作栏中的“刷新”按钮将 textView 重置为零。
public class MainActivity extends Activity {
int counter;
Button add, sub, refresh; // Tried to do this with refresh
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.buttonAdd);
sub = (Button) findViewById(R.id.buttonSub);
display = (TextView) findViewById(R.id.textView);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
counter++;
display.setText("Amount: " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
counter--;
display.setText("Amount: " + counter);
}
});
}
我尝试了几件事,但没有
操作栏项