更新时间:2023-11-22 15:17:40
我知道它的一晚答复,但我最近去通过相同的条件。因此,这里是我的答案,
在
`DialogFragment.Show(FragmentManager经理,字符串标签))`
方法的片段本身设置标签。所以这个标签可以使用如下:
片段dateTo = getActivity()getSupportFragmentManager()findFragmentByTag(dateTo)。;
如果(dateTo!= NULL){
//做一点事 }
一个用例是可以显示更多然后一个片段
的活动,并确定片段,你可以找到与鉴于片段tag.If不是null ,宾果!
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(????){????}
}
};
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!!!