0

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

2 Answers2

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