Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:03:18+00:00 2026-06-02T18:03:18+00:00

Here is my requirement : I’am loading one html file on to a WebView.

  • 0

Here is my requirement :
I’am loading one html file on to a WebView. I have a button in html file to select the date. When i click on that button i want to open android date picker dialog. And after selecting the date, i want to display the selected date in html file. Can anyone guide me. please.
HTML :

 <input type="button" value="Select Date" onClick="openDatePickerDialog()" />
 <p id = "date">--</p>

Javascript :

 function openDatePickerDialog() {
   AndroidFunction.openDatePickerDialog();
 }

function callFromActivity(date) {
document.getElementById('date').innerHTML = date;
 }

My Activity :

  public class MainActivity extends Activity {
WebView myBrowser;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    myBrowser = (WebView)findViewById(R.id.mybrowser);

    final MyJavaScriptInterface myJavaScriptInterface = new MyJavaScriptInterface(this);
    myBrowser.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction");

    myBrowser.getSettings().setJavaScriptEnabled(true); 

    myBrowser.loadUrl("file:///android_asset/test.html");      



}

public class MyJavaScriptInterface 
{
    private int mYear;
    private int mMonth;
    private int mDay;
    static final int DATE_DIALOG_ID = 0;

    Context mContext;

    MyJavaScriptInterface(Context c)
    {
        mContext = c;
    }


    public void openDatePickerDialog()
    { 
        Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        //updateDisplay();

        showDialog(DATE_DIALOG_ID);
    }
    private void updateDisplay() {

        String date = new StringBuilder().append(mMonth + 1).append("-")
        .append(mDay).append("-")
        .append(mYear).append(" ").toString();

        Toast.makeText(getApplicationContext(), date, Toast.LENGTH_LONG).show();

        myBrowser.loadUrl("javascript:callFromActivity(\""+date+"\")");
    }


    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

        public void onDateSet(DatePicker view, int year, 
                int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            updateDisplay();
        }
    };


    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(MainActivity.this,
                    mDateSetListener,
                    mYear, mMonth, mDay);
        }
        return null;
    }

}
 }

Problem : I’am not getting DatePicker Dialog When i click on button. Where i’am going wrong ? Is my approach correct ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:03:19+00:00Added an answer on June 2, 2026 at 6:03 pm
    public void openDatePickerDialog()
    { 
        Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
    
        //updateDisplay();
        DatePickerDialog dp = new DatePickerDialog(this,
                mDateSetListener,
                mYear, mMonth, mDay);
        dp.show();
    }
    

    can you try this once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my requirement: 1. I want my installable to have a custom license agreement
Here is my requirement. I have a client that was sending a specific message
Hey guys, here's my requirement: I have one central App which receives requests from
I have a textbox with calendar button. Here my requirement is I need to
I am creating a installer using WIX, The requirement here is that when the
I want to model messages between users, here is the requirement: User has received
Here is simplified version of my requirement I have a java class say Processor
I have a requirement to send mails through java. Here I am getting error
Here I have 2 requirements: Need a batch file to start a process on
I have an application that has a window similar to the one bellow .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.