替代preferenceFragment与Android支持-V4 [英] Alternatives to PreferenceFragment with android-support-v4

查看:304
本文介绍了替代preferenceFragment与Android支持-V4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来一个突然停止我的应用程序的开发,因为我意识到,preferenceFragments不支持该库。是否有一个菜鸟Android开发者可以用它来克服这一障碍的任何替代方案?

这是我的主要窗口,截至目前

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
< TabHost
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        >

        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =0dp
            机器人:layout_height =0dp
            机器人:layout_weight =0/>

        <的FrameLayout
            机器人:ID =@ +安卓ID / realtabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =0dp
            机器人:layout_weight =1/>
    < / LinearLayout中>

                < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:方向=横向
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =0
            />

< / TabHost>
< / LinearLayout中>
 

有关我TabActivity我使用的东西,我在网上找到。这里有一个片段:

 公共类TabControlActivity扩展FragmentActivity实现TabHost.OnTabChangeListener
{
公共静态最终诠释INSERT_ID = Menu.FIRST;
公共静态TabControlActivity thisCtx;
私人TabHost mTab​​Host;
私人HashMap的mapTabInfo =新的HashMap();
私人TabInfo mLastTab = NULL;

私有类TabInfo {
     私人字符串标签;
     私有类CLSS;
     私人捆绑ARGS;
     私人片段片段;
     TabInfo(字符串标记,类clazz中,捆绑参数){
         this.tag =标签;
         this.clss = clazz所;
         this.args = ARGS;
     }

}

类TabFactory实现TabContentFactory
{

    私人最终语境mContext;

    / **
     * @参数方面
     * /
    公共TabFactory(上下文的背景下){
        mContext =背景;
    }

    / **(非Javadoc中)
     * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String中)
     * /
    公共查看createTabContent(字符串变量){
        视图V =新景(mContext);
        v.setMinimumWidth(0);
        v.setMinimumHeight(0);
        返回伏;
    }

}

... *剪断* ...
 

有没有实现的东西,类似于preferencefragment(或preferenceActivity)使用了Android支持-V4兼容库?

解决方案

添加以下项目作为库项目到应用程序。

https://github.com/kolavar/android-support-v4 - preferencefragment

您可以让一切,包括你的片段的交易,因为它是。当导入 preferenceFragment 类,确保正确的导入头是用户。

 进口android.support.v4 preference preferenceFragment。;
 

而不是

 进口安卓preference preferenceFragment。;
 


更新 - 2015年6月11日

支持-V7的库现在包括 preferenceFragmentCompat 。因此,这将是一个更好的主意,用它。

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 ?

解决方案

Add the following project as a library project to your application.

https://github.com/kolavar/android-support-v4-preferencefragment

You can keep everything including your fragment transaction as it is. When importing the PreferenceFragment class, make sure the correct import header is user.

import android.support.v4.preference.PreferenceFragment;

instead of

import android.preference.PreferenceFragment;


UPDATE - 6/11/2015

Support-v7 library now includes PreferenceFragmentCompat. So it will be a better idea to use it.

这篇关于替代preferenceFragment与Android支持-V4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆