Reputation: 35
I am using a chronometer for counting time in an app it has three buttons start,pause,reset.Once start button has clicked then only pause button should be enabled for clicking and start button should loose it's clicking functionality until the user presses pause or reset button.How to compare the chronometer time with a fixed time in a text view in android can anyone provide me a suitable way in this dilemma
Upvotes: 0
Views: 1496
Reputation: 20885
Usually this is accomplished with a simple subtraction between two long
values which represent a particular instant.
You use an instance of the SimpleDateFormat
class to bridge between an actual time (represented by a Date
object) and a textual representation like 12:32
. Example
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Date start = sdf.parse(text.getText().toString());
Date end = sdf.parse(chronometer.getText().toString());
long difference = end.getTime() - start.getTime();
Regarding the listener part, either you remove listeners or check for some flag at the beginning of the onClick(View)
callback. You may want to enforce the enabled/disabled state with some custom style if appropriate and setEnabled(boolean)
Upvotes: 1
Reputation: 6867
is that what you're looking for?chronometer.getText().toString().equals(yourTextView.getText()) if not, please explain your question
Upvotes: 0