Search code examples
javaandroidandroid-edittextchronometer

How to compare an EditText to Chronometer?


I tried in several ways and I also search a lot but what I found is very confuse to me because I'm relative begginer in Android dev.

I didn't know anything about how to use the chronometer, I passed all the day studing it and I know now how to reset the clock (using ElapsedRealTime) but I don't know how to compare the time on chronometer and the time typed by the user. I read that i could use the Handler or run() but I didn't understand how each one works.

What I want to do:

1: The user will enter a time in mm:ss (same format as chronometer), lets call this t1

2: The user will enter another time, in mm:ss format too. Lets call this t2

3: A message will be displayed in a TextView, the message will appear after t1 minutes and will stay on the screen for t2 minutes, and it'll repeat forever. The result will be: appear, disappear, appear, disappear...

I will place 2 chronometers for it, each one for each time typed.

I'm not asking all the code, just how can I compare a time in the chronometer with a time typed in the EditText, I have (or I think I have) everything planned.

How can I do it? Is there any other easy way to do it?

Hopes I was clear and a sorry for my English.


Solution

  • I continued my search and I did it, I was thinking about delete this post but I'll post what I did here so others can use it.

    MyChronometer.setOnChronometerTickListener(new OnChronometerTickListener()
            {
    
                public void onChronometerTick(Chronometer p1)
                {
    
                    if (MyChronometer.getText().toString().contains(MyEditText.getText().toString()))
                    {
                        //Do something
                    }
                }
        });
    

    I use contains(something) to compare, i don't know why but it didn't work as expected when I used ==something

    Hope it helps someone.