1

I have 4 DatePicker Dialog in my Activity Class which are shown on click of 4 buttons . Now for these datePickerDialog i want to use same listener .

        DatePickerDialog taxPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
        taxPickerDialog.show();

        DatePickerDialog fcPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
        fcPickerDialog.show();
        break;

        DatePickerDialog expiryPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
        expiryPickerDialog.show();


        DatePickerDialog permitPickerDialog = new DatePickerDialog(getCurrentContext(),dateSetListener,calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DATE));
        permitPickerDialog.show();

Now i want a use listener but dnot know how to implement this ???

DatePickerDialog.OnDateSetListener dateSetListener =new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int month, int day) {
    switch(????){????}
}
};
Code_Life
  • 5,742
  • 4
  • 29
  • 49
  • Well for this you might like to see http://stackoverflow.com/questions/3734981/multiple-datepickers-in-same-activity – Aditya Pratap Singh Aug 31 '12 at 04:53
  • maybe this approach could be useful for you: http://stackoverflow.com/questions/3734981/multiple-datepickers-in-same-activity – Lara Sep 10 '12 at 08:38

3 Answers3

0

Hope you might have resolved this by now. Just putting an idea - "you can set some sort of ID or TAG for DatePicker associated with each Dialog and then you can differentiate by querying what you have set (ID/TAG)."

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
iuq
  • 1,487
  • 1
  • 20
  • 42
  • Thanks for reply .. but this issue is still open . I cant use ID as i dnt have it because DatePicker is created on Java Code not on Xml , – Code_Life Jul 17 '12 at 12:06
  • Mohit, you can add ID in code as well using View's setId() method. – iuq Jul 18 '12 at 06:58
0

I know its a late reply but i went through with the same condition recently . So here is my answer ,

the

`DialogFragment.Show(FragmentManager manager, String tag))`

method is set tag for Fragment itself . so this tag can be use as follows :

Fragment dateTo=getActivity().getSupportFragmentManager().findFragmentByTag("dateTo");
            if(dateTo!=null){
                //do something

            } 

one use case is you can display more then one Fragment in a activity and to identify the fragment you can find that fragment with the given tag.If it is not null, bingo!!!

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
nitesh goel
  • 6,338
  • 2
  • 29
  • 38
0
class DPlistener implements OnDateSetListener
{

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {

         //you can here
        if (view.equals(expiryPickerDialog))
        {
      //do needfull
              }
    }}

and register this listener in your datepicker views., make sure this class is inner class of your activity

AAnkit
  • 27,299
  • 12
  • 60
  • 71