Giter VIP home page Giter VIP logo

Comments (6)

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 29, 2024

Here's a sample code, if anyone wants to check out:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/container"
 android:layout_width="match_parent"
 android:layout_height="match_parent"/>

SettingsActivity.java

public class SettingsActivity extends ActionBarActivity
  {
  public class SettingsFragment extends PreferenceFragment
    {
    @Override
    public void onCreate(final Bundle savedInstanceState)
      {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.pref_general);
      }
    }

  @Override
  protected void onCreate(final Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportFragmentManager().beginTransaction().add(R.id.container,new SettingsFragment()).commit();
    }
  }

pref_general.xml

<PreferenceCategory android:title="PreferenceCategory" >
    <CheckBoxPreference
        android:key="checkbox_preference"
        android:summary="CheckBoxPreference"
        android:title="CheckBoxPreference" />
</PreferenceCategory>

from android-support-v4-preferencefragment.

gstorer avatar gstorer commented on July 29, 2024

As someone not that familiar with fragments (I'm in the process of porting an old app from Action Bar Sherlock activities to ActionBarActivities with fragments), this was actually really helpful. Thanks.

from android-support-v4-preferencefragment.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 29, 2024

@gstorer I've also made a library that doesn't require you to use a fragment for the preferences, if you wish:
https://github.com/AndroidDeveloperLB/MaterialStuffLibrary

from android-support-v4-preferencefragment.

michzio avatar michzio commented on July 29, 2024

I have a question:
This PreferenceFragment implementation can by used in a such scheme:

  1. as replacement for preHoneycomb PreferenceActivity enabling adding the same functionality inside ActionBarActivity (with ActionBar) like Preference Fragment -> Preference Screens, but without enabling usage of android PreferenceActivity -> Preference Headers + Preference Fragments -> Preference Screens
    or
  2. it could be used in conjunction with Android PreferenceActivity class postHoneycomb where this Activity provide preference header and associated Prefrence Fragments can be implemented with this android-support-v4-preferencefragment and it will provide preference screens... but if so what with Preference Activity on pre-honycomb, what I know there is only one Preference Activity class so on pre-honycomb it will not provider preference headers/action bard and so on ?

Please clarify scheme of use that works on pre-Honycomb and post-Honeycomb:

  1. it enables implementing only as this replacement for pre-Honycomb PreferenceActivity scheme
    or
  2. more sophisticated usage as post-Honeycomb with PreferenceActivity -> Preference Headers

from android-support-v4-preferencefragment.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 29, 2024

@michzio Sadly, it's just the simple usage. no headers and such, as they weren't introduced on pre-Honeycomb, and the support library doesn't have those...

from android-support-v4-preferencefragment.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 29, 2024

@michzio If you wish, you can check out my library that adds actionBar for PreferenceActivity:
https://github.com/AndroidDeveloperLB/ActionBarPreferenceActivity
A similar thing can be done here.

from android-support-v4-preferencefragment.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.