Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to PreferenceFragment with android-support-v4

I've come to a sudden halt in the development of my app as I realized that PreferenceFragments weren't supported in this library. Are there any alternatives that a rookie android developer can use to overcome this obstacle ?

This is my main window as of right now

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"> <TabHost     android:id="@android:id/tabhost"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <LinearLayout         android:orientation="vertical"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         >          <FrameLayout             android:id="@android:id/tabcontent"             android:layout_width="0dp"             android:layout_height="0dp"             android:layout_weight="0"/>          <FrameLayout             android:id="@+android:id/realtabcontent"             android:layout_width="fill_parent"             android:layout_height="0dp"             android:layout_weight="1"/>     </LinearLayout>                  <TabWidget             android:id="@android:id/tabs"             android:orientation="horizontal"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_weight="0"             />  </TabHost> </LinearLayout> 

For my TabActivity I'm using something I found online. Here's a snippet:

public class TabControlActivity extends FragmentActivity implements TabHost.OnTabChangeListener  { public static final int INSERT_ID = Menu.FIRST; public static TabControlActivity thisCtx; private TabHost mTabHost; private HashMap mapTabInfo = new HashMap(); private TabInfo mLastTab = null;  private class TabInfo {      private String tag;      private Class clss;      private Bundle args;      private Fragment fragment;      TabInfo(String tag, Class clazz, Bundle args) {          this.tag = tag;          this.clss = clazz;          this.args = args;      }  }  class TabFactory implements TabContentFactory  {      private final Context mContext;      /**      * @param context      */     public TabFactory(Context context) {         mContext = context;     }      /** (non-Javadoc)      * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)      */     public View createTabContent(String tag) {         View v = new View(mContext);         v.setMinimumWidth(0);         v.setMinimumHeight(0);         return v;     }  }  ...*snip*... 

Is there any to implement something that resembles a preferencefragment(or preferenceActivity) using the android-support-v4 compatibility library ?

like image 772
CodePrimate Avatar asked Mar 20 '12 08:03

CodePrimate


1 Answers

I know this is an old question, but you can now use PreferenceFragmentCompat from com.android.support:preference-v7:23.3.0

like image 101
Lucius Avatar answered Sep 28 '22 17:09

Lucius