I wanted to use date picker inside my custom dialog. On button click calendar will open to choose date for user. I have Button inside my customDilaog class and on that button click I want to open calendar view. My app crashes if click this button. I have done with this.
CustomDialog.java
public class CustomDialog extends Dialog implements android.view.View.OnClickListener {
private Button date;
DateFormat format = DateFormat.getDateInstance();
Calendar calender = Calendar.getInstance();
public CustomDialog(Context context) {
super(context);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
date=(Button)findViewById(R.id.dateText2);
}
public void onClick(View v) {
if (v.getId()==R.id.datePick) {
openDatePicker(v);
//another if-else statements
}
public void updateDate(){
date.setText(format.format(calender.getTime()));
}
public void setDate(){
new DatePickerDialog(getContext(),dp,calender.get(Calendar.YEAR) ,calender.get(Calendar.MONTH),calender.get(Calendar.DAY_OF_MONTH)).show();
}
DatePickerDialog.OnDateSetListener dp = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
calender.set(Calendar.YEAR,year);
calender.set(Calendar.MONTH, monthOfYear);
calender.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDate();
}
};
}
I don't know where I made mistake.
use this appropriately