I want to use DatePickerFragment inside PreferenceFragment for the date of birth. Can we use it like the way we use EditTextPreference or anything else we have to use. I know how DatePickerFragemnt and PreferenceFragment basic functionality.
Any help is appriciated.
Edited
.xml file for Preferences
<PreferenceCategory android:title="@string/pref_profile_setting" >
<EditTextPreference
android:title="@string/pref_user_name"
android:summary="@string/pref_user_name_summary"
android:key="prefName"/>
<com.mypkg.DatePickerFragment
android:title="@string/pref_gender"
android:summary="@string/pref_postcode_summary"
android:key="prefDob"
/>
<ListPreference
android:title="@string/pref_gender"
android:summary="@string/pref_postcode_summary"
android:key="prefGender"
android:entries="@array/gender"
android:entryValues="@array/gender_type"/>
</PreferenceCategory>
</PreferenceScreen>
Class that extended the PreferenceFragment
public class MyFragment extends PreferenceFragment implements OnPreferenceChangeListener{
private EditTextPreference etNamePref;
private ListPreference lvGenderPref;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_settings);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle paramBundle) {
View view = inflater.inflate(R.layout.fragment_settings, container, false);
initView();
return view;
}
private void initView() {
etNamePref = (EditTextPreference)findPreference(ConstantsUtil.PREF_NAME);
etNamePref.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if(key.equalsIgnoreCase(ConstantsUtil.PREF_NAME)){
etNamePref.setSummary(newValue.toString());
}
return false;
}
}
Add on Preference Tag in your .xml file
In .java class implement the OnPreferenceClickListener and below code
inside onClick call the DatePickerFragment like below
Done !