简体   繁体   中英

How to get current entryValues from ListPreference in Fragments

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.record_fragment, container, false);
    ListPreference listPreference = (ListPreference) findPreference("formats_listpref");
    CharSequence currText = listPreference.getEntry();
    String currValue = listPreference.getValue();
    return v;
}

The method findPreference(String) is undefined for the type Browse_Fragment

I want to get the currently selected entryValues from ListPreference, I can get the value from Activity but when i use the same code in fragments, its not working findPreference(String) is undefined i also tried getActivity().findPreference but still it is showing as undefined. thanks in advance .

I would check that your fragment extends PreferenceFragment ie

public class YourFragment extends PreferenceFragment {
...
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM