I have an Android app, running a WebView that loads a certain page, also part of the app. I want to use the Android DatePicker to get a date from the user and set the value on an input inside the page in the WebView.
The DatePickerDialog opens when the user clicks the input, but when i get the return of the date selection, i can't run the loadUrl method to set the value in the input, it gives me an error and the app crashes.
A little bit of code (It's a test code, so don't mind if it is a bit out of context):
Class i provide to the WebView:
public class webViewInterface {
public void openDatePicker(){
showDialog(0);
}
}
Javascript function on the page, called on the click of the input:
function openDatePicker() {
if (objAndroid != null) objAndroid.openDatePicker();
}
Listener for the date selection
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mWebView.loadUrl("javascript:setReturnDate();");
}
};
Javascript function that sets a value on the input
function setReturnDate() {
document.getElementById('txtAgency').value = '9999';
}
Any ideas?
Thanks in advance.