简体   繁体   中英

Android - Get EditText and show dialog

I want my application can get user's input of time (HH:mm) from EditText widget. Based on this time value my app needs to show a dialog when current time matches entered time.

Gaauwe

* Edit *

I want to place an EditText widget in my app. A user will fill it with some time value (eg 10:30). Then when real time (10:30) come up a dialog will be shown.

I think you can use the AlarmManager for this.

I d suggest you have a look at some tutorials like these to help you get started

http://michael.theirwinfamily.net/articles/android/android-creating-alarm-alarmmanager

http://android.arnodenhond.com/tutorials/alarm-notification

try this :
use the service : then when user enter time starts a service when system time and user entered time match the shows..

That is not too difficult. When user finished editing you EditText, read the time value and create instance of AlarmManager with start time calculated as difference between current time and whatever user wrote in the EditText. Better to use TimePicker to avoid parsing user`s input. Add receiver for you AlarmManager, receiver will start Service which will show dialog or do anything you want. You need to use AlarmManager because if your device is sleeping nothing will wake it up except system call like AlarmManager. @Zortkun 's post with links will help you to figure out how manage AlarmManager.

You can pull the data out of the EditText with:

findViewById(R.id.yourEditText).getText().toString();

The rest of your question I didn't understand.

RAW WAY!

So when user put text inside edittext and click button, you could save text in this way:

String time = findViewById(R.id.yourEditText).getText().toString();

and start a thread that check for time, and when time is equal to user's string time, you can show a dialog :)

Thread t = new Thread(new Runnable(){
   public void run(){
      while(new Date().getLocalTime()!=usersTime){ // is just pseudocode
          Dialog.show();
      }   
   }
});

I'll try to understand...

Seeing as you know how to pull the text from an EditText, you'll need an if statement.

Something that compares that time to the current time.

        if (editTime == realTime) {

    Toast.makeText(getApplicationContext(), "RING RING RING",
                            Toast.LENGTH_SHORT).show();

}

Use something like this:

Read this to figure out how to get a string of current time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM