Reputation: 651
I am developing my program but it seems It really giving me hard time regarding TextView.XD Just like in Scoreboard. Increasing the value of score as you click the TextView assigned to it.
This is my code:
private OnClickListener mHscoreListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
h1++;
TextView HScore = (TextView) findViewById(R.id.hscore);
HScore.setText(h1);
};
};
The above code not working and I don't know why.
Upvotes: 0
Views: 144
Reputation: 11097
I think you should set onClickListener to TextView HScore.
Try this way Define HScore and h1 as class variable.
HScore = (TextView) findViewById(R.id.hscore);
OnClickListener mHscoreListener = new OnClickListener()
{
public void onClick(View v)
{
// DO INCREASE
h1++;
HScore.setText(h1 + "");
};
};
HScore.setOnClickListener(mHscoreListener);
Upvotes: 1
Reputation: 33509
What type is h1
?
You may need to use h1.toString()
private OnClickListener mHscoreListener = new OnClickListener() {
public void onClick(View v) {
//DO INCREASE
h1++;
TextView HScore = (TextView) findViewById(R.id.hscore);
HScore.setText(h1.toString());
};
};
Upvotes: 0