thanks for the help but I\'m still struggling. I did this:
Button in xml:
I cant actually figure out what the increment textview means ....
May be adding more textviews or increasing the value inside the textview. I will go with later.
Context context;
TextView tv;
Button increamenter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
tv=(TextView)findViewById(R.id.textView1);
incrementer=(Button)findViewById(R.id.button1);
context=this;
incrementer.setOnClickListener(new View.OnClickListener(){
try
{
String presentValStr=tv.getText().toString();
int presentIntVal=Integer.parseInt(presentValStr);
presentIntVal++;
tv.setText(String.valueOf(presentIntVal));
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(context,"Some error :(",2000).show();
}
});
}
In your class create:
int score = 0;
And then;
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// score operation like score += increment_value;
t1.setText(""+score);
}
});
If you need to "save" the score ocne you quit the application, you need to use SharedPreferences to show/update the value.