Skip to content

Instantly share code, notes, and snippets.

@getsadzeg
Last active April 19, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getsadzeg/37c74d1c83989b23d9f995b6f9dd3915 to your computer and use it in GitHub Desktop.
Save getsadzeg/37c74d1c83989b23d9f995b6f9dd3915 to your computer and use it in GitHub Desktop.
Fragment + Activity = <3

Basic outline of Resources/Activity/Fragment connection:

First, we make SettingsActivity. Then, we create SettingsFragment, in which we write addPreferencesFromResource(R.xml.pref_settings); to connect it with a resource we created in xml resource directory.

Finally, we make root layout of activity_settings.xml a fragment, specifically SettingsFragment, with android:name="com.example.android.myapp.SettingsFragment"

Important note: Must not forget adding a style in styles.xml. Otherwise, app will crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment