I have an app and I am trying to limit the number of button clicks to five, then once the user has pressed this button five times it disables, however I am getting the above error and I am not sure why. Any ideas?
buttonadd.setOnClickListener(new OnClickListener () {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity3.class);
startActivity(intent);
int clicks = 0;
clicks++;
if (clicks >= 5){
buttonadd.setEnabled(false);
}
SharedPreferences prefs = Context.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("clicks", clicks);
editor.apply();
}
});
0 comments:
Post a Comment