2016-04-12 18 views
0

i mein picker Dialog Set einrichten, kann aber für sie Mindest Datum in meinem Code nicht gesetzt ist, helfen mir jemand hier ist mein Code:Mindestdatum für Datumsauswahl Dialog android

public class PPlanAppActivity extends AppCompatActivity implements View.OnClickListener,DatePickerDialog.OnDateSetListener{ 
    public EditText tppdate,tpprtype,tpptaxperiod,tppamntdue, 
      tpp1pd,tpp1pa,tpp2pd,tpp2pa,tpp3pd,tpp3pa; 

    private int pYear; 
    private int pMonth; 
    private int pDay; 
    static final int DATE_DIALOG_ID = 0; 
    public static final String PREFS ="useremail"; 
    private DatePickerDialog.OnDateSetListener pDateSetListener = 
      new DatePickerDialog.OnDateSetListener() { 


       public void onDateSet(DatePicker view, int year, 
             int monthOfYear, int dayOfMonth) { 
        pYear = year; 
        pMonth = monthOfYear; 
        pDay = dayOfMonth; 

        updateDisplay(); 
        displayToast(); 
       } 
      }; 

    /** Updates the date in the TextView */ 
    private void updateDisplay() { 
     tpp1pd.setText(
       new StringBuilder() 
         // Month is 0 based so add 1 
         .append(pMonth + 1).append("/") 
         .append(pDay).append("/") 
         .append(pYear).append(" ")); 
     tpp2pd.setText(
       new StringBuilder() 
         // Month is 0 based so add 1 
         .append(pMonth + 1).append("/") 
         .append(pDay).append("/") 
         .append(pYear).append(" ")); 
     tpp3pd.setText(
       new StringBuilder() 
         // Month is 0 based so add 1 
         .append(pMonth + 1).append("/") 
         .append(pDay).append("/") 
         .append(pYear).append(" ")); 
    } 


    /** Displays a notification when the date is updated */ 
    private void displayToast() { 
     Toast.makeText(this, new StringBuilder().append("Date choosen is ").append(tpp1pd.getText()), Toast.LENGTH_SHORT).show(); 

    } 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_pplan_app); 


    tppdate =(EditText)findViewById(R.id.padatetxt); 

    long date = System.currentTimeMillis(); 

    final SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); 
    String dateString = sdf.format(date); 
    tppdate.setText(dateString); 

     final Calendar c=Calendar.getInstance(); 

     tpp1pd=(EditText)findViewById(R.id.pa1stpdate); 
     tpp1pd.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(DATE_DIALOG_ID); 
      } 
     }); 
     tpp2pd=(EditText)findViewById(R.id.pa2ndpdate); 
     tpp2pd.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(DATE_DIALOG_ID); 
      } 
     }); 
     tpp3pd=(EditText)findViewById(R.id.pa3rdpdate); 
     tpp3pd.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(DATE_DIALOG_ID); 
      } 
     }); 




     /** Get the current date */ 
     final Calendar cal = Calendar.getInstance(); 
     pYear = cal.get(Calendar.YEAR); 
     pMonth = cal.get(Calendar.MONTH); 
     pDay = cal.get(Calendar.DAY_OF_MONTH); 

     /** Display the current date in the TextView */ 
     // updateDisplay(); 


} 

    /** Create a new dialog for date picker */ 
    @Override 
    protected Dialog onCreateDialog(int id) { 
     switch (id) { 
      case DATE_DIALOG_ID: 
       return new DatePickerDialog(this, 
         pDateSetListener, 
         pYear, pMonth, pDay); 
     } 
     return null; 
    } 

Antwort

0

Ihre DatePickerDialog wie folgt erstellen -

final DatePickerDialog datePickerDialog = new DatePickerDialog(this, 
          pDateSetListener, 
          pYear, pMonth, pDay); 
//Set minimum date 
datePickerDialog.getDatePicker().setMinDate(<minimum_date_in_millis_here>); 

Und zeigen, wie diese -

tpp3pd.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       datePickerDialog.show(); 
      } 
     }); 

Kein nee d in diesem Fall onCreateDialog() haben.