Reputation: 31
Trying to make a "click counter" game in android studio.
int clicked = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView text = (TextView) findViewById(R.id.counter);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clicked++;
text.setText(clicked);
}
});
}
This is the code i set up for the counter. Any ideas about what i might be doing wrong?
Upvotes: 2
Views: 47
Reputation: 519
Try: @Override public void onClick(View v) { clicked+=1; text.setText(String.valueOf(clicked);
text.invalidate();}
Upvotes: 2