I'm trying to load preferences into my fragment, which works, but I can't seem to find a way of changing the layout. Right now I have this problem:
This is my code:
public class SettingsFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
//getFragmentManager().beginTransaction().add(android.R.id.content, new MyPreferenceFragment()).commit();
getFragmentManager().beginTransaction().add(android.R.id.content, new MyPreferenceFragment()).commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_settings, container, false);
}
public static class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
On this stackoverflow theyre doing what I'm trying to achieve, except that setContentView doesn't work in a fragment How to add a button to PreferenceScreen
Here's my preference.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="username"
android:summary="Please provide your username"
android:title="Your Name">
</EditTextPreference>
<CheckBoxPreference
android:defaultValue="false"
android:key="applicationUpdates"
android:summary="This option if selected will allow the application to check for latest versions."
android:title="Application Updates" />
<ListPreference
android:defaultValue="1"
android:entries="@array/listArray"
android:entryValues="@array/listValues"
android:key="downloadType"
android:summary="Select the kind of data that you would like to download"
android:title="Download Details" />
And my fragment xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nl.shacklez.mijnreceptenofficialv1.SettingsFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>