Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>there's also a great tutorial <a href="http://javapapers.com/android/android-datepicker/" rel="nofollow">here</a> which also has source code to download.</p> <p>One thing to note, when compiling the source code, you need make SelectDateFragment class "static" in javapapers code as well as make populateSetDate() method static, and I also moved this code:</p> <p><code>mEdit = (EditText)findViewById(R.id.editText1);</code></p> <p>to the onCreate() method. After that you could be able to compile the code.</p> <p>MainActivity should look like this in the end after editing:</p> <pre><code>package com.javapapers.andoiddatepicker; import java.util.Calendar; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.DatePicker; import android.widget.EditText; public class MainActivity extends FragmentActivity { private static EditText mEdit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mEdit = (EditText) findViewById(R.id.editText1); } public void selectDate(View view) { DialogFragment newFragment = new SelectDateFragment(); newFragment.show(getSupportFragmentManager(), "DatePicker"); } public static void populateSetDate(int year, int month, int day) { mEdit.setText(month + "/" + day + "/" + year); } public static class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(getActivity(), this, year, month, day); } public void onDateSet(DatePicker view, int year, int month, int day) { populateSetDate(year, month+1, day); } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload