Sai
Sai

Reputation: 15738

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 .

Upvotes: 0

Views: 195

Answers (1)

Andy B
Andy B

Reputation: 753

I would check that your fragment extends PreferenceFragment i.e.

public class YourFragment extends PreferenceFragment {
...
}

Hope this helps.

Upvotes: 2

Related Questions