SharedPreferences
allows you to store persistent data within your app, and you can get current time by System.currentTimeMillis()
final long DURATION = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
yourButton.setOnClickListener(
new OnClickListener(){
@Override
public void onClick(View v) {
long currentTime = System.currentTimeMillis();
SharedPreferences settings = getPreferences(MODE_PRIVATE);
if((currentTime - settings.getLong("last_click", 0)) > DURATION) {
// Save the new click time
settings.edit().putLong("last_click", currentTime).commit();
// Do your stuff here!
} else {
// Less than 24 hours, show your toast here!
}
}
}
);