Simple Datpicker For The Android
I am trying to launch DataPicker on click of the edit text What am i trying to do:: there are tow edit text I want to launch datepicker from both edit text What i have done ::
Solution 1:
You just implements Edittext onClickListner onClick() Event:
edt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub// new DatePickerDialog(ProximityActivity.this, dateD, myCalendar//.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),//myCalendar.get(Calendar.DAY_OF_MONTH)).show();//Load your DiaglogFragment Over here
}
});
Solution 2:
DatePicker is not launching because you have not set the onClickListener
for your EditText
in your code.
Set the click listener as below for both your EditText.
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt=(EditText)findViewById(R.id.editText1);
edt2=(EditText)findViewById(R.id.editText2);
SimpleDateFormat sdf = newSimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
Calendar c1=Calendar.getInstance();
c1.setTime(newDate());
c.setTime(newDate()); // Now use today date.
c.add(Calendar.DATE, 7); // Adding 7 daysStringToDate = sdf.format(c.getTime());
StringFromDate = sdf.format(c1.getTime());
edt2.setText(FromDate);
edt.setText(ToDate);
edt2.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
selectDate(v);
}
});
edt.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
selectDate(v); //Pass the View as parameter.
}
});
}
Solution 3:
Didn't you forget to set your onClickListener in your onCreate
? Or is it handle in your xml?
edt2.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
selectDate(null);//I set null cause I don't know in the function what should the view be.
}
});
Post a Comment for "Simple Datpicker For The Android"