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
Asked
Active
Viewed 1,494 times
0
-
i don't understand the question – njzk2 Oct 22 '12 at 14:17
-
on starting chronometer by clicking start-button that should enable pause button and disable start button and compare the time with a fixed time in a textview – user1705339 Oct 22 '12 at 14:20
-
yes? and what have you tried? (also, that's not a dilemma) – njzk2 Oct 22 '12 at 14:22
-
See i am not a good spokeperson but i want to achieve above can you help me – user1705339 Oct 22 '12 at 14:24
-
doesn't change the question : "what have you tried?" – njzk2 Oct 22 '12 at 15:08
2 Answers
1
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)

Raffaele
- 20,627
- 6
- 47
- 86
0
is that what you're looking for?chronometer.getText().toString().equals(yourTextView.getText()) if not, please explain your question

Udi Oshi
- 6,787
- 7
- 47
- 65
-
yeah i already did thatit should compare when i click on stop button i have written that in if condition bbut not working – user1705339 Oct 22 '12 at 14:25