This question is about TimePicker behavior in Android.
To get the value of the Hour and the Minute I use getCurrentHour() and getCurrentMinute().
At first I found out that changes made by the user using the phone keyboard where not registered so calling getCurrentHour() or getCurrentMinute() did not show the values changed in the texboxes inside the widget.
This was quickly solved using setAddStatesFromChildren(true); With this I get those changes.
Now, my problem is that those changes are only registered if timepicker looses focus.
So, getting the value from timepicker inside a button gets a wrong value because it hasn't loose focus.
Any help?
What I need is: Can I force a timepicker to loose focus and get the real written value in text boxes?
I solved it and I write it here for someone who needs it.
Thanks to "Tarun Maheshwari" I found what I needed:
On onCreate do something like this:
MyTimerPicker.setAddStatesFromChildren(true);
On the onClick method, when getting the values, do this:
MyTimerPicker.clearFocus();
int iHour = MyTimerPicker.getCurrentHour();
int iMinute = MyTimerPicker.getCurrentMinute();
Call clearFocus() on the timepicker view after you get onTimeChanged callback.
Related
I want to insert text from field into a String array every time the add button is pressed, and when done so, the field should empty itself for a new string.
Here is my code:
Editor note: no code provided as example, only a screenshot of the code
Is the add function ever called? Otherwise you are sitting with a button without an onClickListener.
Try assigning The onClickListener in oncreate instead.
In one of my screen i am using text watcher to check value against a range and for invalid range color of text is being changed.
Now there is one more requirement.
Along with EditText i need to use CheckBox to set completely different range.
The problem i am facing is that changing the checkbox value requires to call afterTextChanged in which i have put all validations for both set of ranges.
So basically my requirement is to update textWatcher anyhow so that afterTextChanged get called after i change value of checkbox.
I get a strange feeling that i am forgetting something very simple here,if so please let me know.
Thanks in advance.
Perhaps move your code from the callback in the textWatcher and put it into another function ie
private void checkRange() {
// do checks here
String color = text.getEditableText().toString();
}
and call this method from your textWatcher and from the listener on the checkbox.
I would like to highlight that I am looking for a Xamarin solution. I have found Java solutions, but I can't seem to convert them to Xamarin. I want to have the user set their birthday and then have the app calculate their age, and display it as text. I have everything functioning. All I am looking to do is change the text on the "ok" button to "Calculate age." I am able to change the text, but the button doesn't grab the date from the picker then. This is how I create my datepicker:
DatePickerDialog setDate = new DatePickerDialog(this, onDateSet, date.Year, date.Month-1, date.Day);
then I use this method to change the text
setDate.SetButton("calculate age", EventHandler<DialogClickEventArgs>)
I have created an EventHandler called Age use for the second argument. What code do I put in the EventHandler to make the button function like the "ok" button? if I set handler:null the method works, I can also get the method to do other things, change text in textbox for a example. Any solution is welcomed.
Wow. No love for Xamarin? I discovered the solution was much simpler. Following from what I learned here: Change DatePickerDialog's button texts. I began throwing darts into the code and this is what stuck. Where I set handler to null I simply set listener to the dialog object like so. setDate.SetButton ("calculate age", listener:setDate);
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 (e.g. 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
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.
try this :
use the service : then when user enter time starts a service when system time and user entered time match the shows..
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.
I have a DatePicker-view as well as a TimePicker-view in my layout, and everytime the date or time is changed I want to update a value. On the TimePicker I can simply set a setOnTimeChangedListener, but nothing corresponding exists for the DatePicker. A listener called OnDateChangedListener can be set in the init()-function, but it does not trigger each time the date is changed. Is there a corresponding listener, or is there a hack available to solve this problem in a satisfactory manner?
http://developer.android.com/intl/de/reference/android/widget/DatePicker.html
http://developer.android.com/intl/de/reference/android/widget/TimePicker.html
Cheers,
A listener called
OnDateChangedListener can be set in
the init()-function, but it does not
trigger each time the date is changed.
According to the source code, it is called each time the date is changed. So, try that again.