i have tried to future dates to disable ,in my code using 2.3 ginger bird version in api 9 datepicker disable future dates its not there. now i have tried useing 4.0 version , i have done searching i got this but i have tried to implementing this in my code not able to fix
http://stackoverflow.com/questions/6116920/disable-future-dates-in-android-date-picker how to resolve this can any one help .how to disable future dates ,not beyond current date,month and year. import java.util.Calendar; import java.util.Date; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.DatePicker; public class samplecalender extends Activity implements OnClickListener { private static final int DATE_DIALOG_ID_1 = 1; private static final int DATE_DIALOG_ID_2 = 2; private static final int SECOND_ACTIVITY = 3; private int mYear, mDay, mMonth; public String month = null, day = null, firstDate = null, secondDate = null; private Button buttonFirstDate = null, buttonSecondDate = null, buttonCallAnotherActivity = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initControls(); } private void initControls() { try { buttonFirstDate = (Button) findViewById(R.id.buttonFirstDate); buttonFirstDate.setOnClickListener(this); buttonSecondDate = (Button) findViewById(R.id.buttonSecondDate); buttonSecondDate.setOnClickListener(this); buttonCallAnotherActivity = (Button) findViewById(R.id.buttonCallAnotherActivity); buttonCallAnotherActivity.setOnClickListener(this); buttonCallAnotherActivity.setVisibility(View.GONE); } catch (Exception e) { e.printStackTrace(); } } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID_1: DatePickerDialog dil = new DatePickerDialog(this, datePickerListenerFirst,Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), (Calendar.getInstance().get(Calendar.DAY_OF_MONTH))); //dil.getDatePicker().setMaxDate(new Date()); return dil; case DATE_DIALOG_ID_2: { return new DatePickerDialog(this, datePickerListenerSecond, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), (Calendar.getInstance().get(Calendar.DAY_OF_MONTH))-1); } default: return null; } } private DatePickerDialog.OnDateSetListener datePickerListenerFirst = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; /*if(monthOfYear+1<=Calendar.getInstance(Calendar.MONTH).CONTEXT_RESTRICTED)) mMonth = monthOfYear + 1; mYear = year;*/ mDay = dayOfMonth; if (mMonth > 9) { mYear = year; month = "1" + mMonth; //if(month = "1" + mMonth) } else month = String.valueOf(mMonth); if (mDay <= 9) { day = "0" + mDay; } else day = String.valueOf(mDay); firstDate = day + "/" + month + "/" + mYear; buttonFirstDate.setText(firstDate); } }; private DatePickerDialog.OnDateSetListener datePickerListenerSecond = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear + 1; mYear = year; mDay = dayOfMonth; if (mMonth <= 9) { month = "0" + mMonth; } else month = String.valueOf(mMonth); if (mDay <= 9) { day = "0" + mDay; } else day = String.valueOf(mDay); secondDate = day + "/" + month + "/" + mYear; buttonSecondDate.setText(secondDate); buttonCallAnotherActivity.setVisibility(View.VISIBLE); } }; public void onClick(View v) { try { switch (v.getId()) { case R.id.buttonFirstDate: Calendar cal = Calendar.getInstance(); mYear = cal.get(Calendar.YEAR); mMonth = cal.get(Calendar.MONTH); mDay = cal.get(Calendar.DAY_OF_MONTH); showDialog(DATE_DIALOG_ID_1); break; case R.id.buttonSecondDate: Calendar calendar = Calendar.getInstance(); mYear = calendar.get(Calendar.YEAR); mMonth = calendar.get(Calendar.MONTH); mDay = calendar.get(Calendar.DAY_OF_MONTH); showDialog(DATE_DIALOG_ID_2); break; case R.id.buttonCallAnotherActivity: Intent intent = new Intent(samplecalender.this,GoScreenActivity.class); intent.putExtra("firstDate", firstDate); intent.putExtra("secondDate", secondDate); startActivityForResult(intent, SECOND_ACTIVITY); break; default: break; } } catch (Exception e) { e.printStackTrace(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == SECOND_ACTIVITY && resultCode == RESULT_OK) { // Do What you want buttonSecondDate.setVisibility(View.GONE); } } } On Thu, Jul 26, 2012 at 11:22 PM, TreKing <[email protected]> wrote: > On Thu, Jul 26, 2012 at 11:38 AM, Jagadeesh <[email protected]>wrote: > >> Hi How to restrict the future dates in Datepicker dialog, > > > Define "restrict future dates". > > > ------------------------------------------------------------------------------------------------- > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > transit tracking app for Android-powered devices > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

