Answer the question
In order to leave comments, you need to log in
OnClick click processing is not saved, how to save?
Application logic: open -> click on the button -> the text from the database appears and the countdown starts -> after the time has elapsed, it becomes possible to click on the button again
Problem: I made it so that the timer is saved, i. after closing the application, the timer continues to run BUT when the button is opened again, and only after it is pressed, a timer with the corresponding value appears Needed
: so that when you open it again, the button is not visible, but the running timer and the message from the database remain visible
Code:
@Override
public void onClick(final View v) {
String product = "";
Cursor cursor = mDb.rawQuery("SELECT * FROM Guru ORDER BY RANDOM() LIMIT 1;", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
product = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
textView.setText(product);
v.setVisibility(View.GONE);
final long timer = 12 * 60 * 60 * 1000 - (guruTime+guruSeve.getLong("TIME2",0));
v.postDelayed(new Runnable() {
public void run() {
v.setVisibility(View.VISIBLE);
}
}, timer);
final SharedPreferences.Editor editor = guruSeve.edit();
editor.putLong("TIME2",guruTime+guruSeve.getLong("TIME2",0));
editor.commit();
new CountDownTimer(timer,1000) {
public void onTick(long millisUntilFinished) {
mTimer.setText( "Осталось:" + " " + DateUtils.formatElapsedTime(millisUntilFinished / 1000));
}
public void onFinish() {
mTimer.setText("");
}
}
.start();
guruTime=System.currentTimeMillis();
SharedPreferences.Editor editor2 = guruSeve.edit();
editor2.putLong("TIME",guruTime);
editor2.commit();
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question