0

我正在将 HoloEveryWhere 与 ViewPagerIndicator 一起使用,并尝试在PreferenceFragment(HoloEveryWhere) 中使用PreferenceActivity(HoloEveryWhere) 并且无法修复错误...我必须忽略某些东西

部分日志:

01-13 20:10:04.310: E/AndroidRuntime(29939): FATAL EXCEPTION: main
01-13 20:10:04.310: E/AndroidRuntime(29939): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.LayoutInflater.tryCreateView(LayoutInflater.java:357)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:306)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:285)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:270)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.preference.Preference.onCreateView(Preference.java:535)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.preference.Preference.getView(Preference.java:425)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:160)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at org.holoeverywhere.widget.ListView$ListAdapterWrapper.getView(ListView.java:341)
01-13 20:10:04.310: E/AndroidRuntime(29939):    at android.widget.AbsListView.obtainView(AbsListView.java:2273)

我的PreferenceActivity

import org.holoeverywhere.app.Fragment;
import org.holoeverywhere.preference.PreferenceActivity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.TitlePageIndicator;


public class Test extends PreferenceActivity {

    ViewPager Pager;

    enum PageInfo {
        One(R.string.one), Two(R.string.two), Three(R.string.three); 
        int titleResId;

        PageInfo(int titleResId) {
            this.titleResId = titleResId;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Pager = (ViewPager) findViewById(R.id.pager);
        Pager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
        ((TitlePageIndicator) findViewById(R.id.titles)).setViewPager(Pager);
    }//end method

    class PagerAdapter extends FragmentPagerAdapter {

        public PagerAdapter(FragmentManager fm) {
            super(fm);
        }//end method

        @Override
        public Fragment getItem(int position) {

            if (PageInfo.One.ordinal() == position) {
                return new OneFragment();
            } else if (PageInfo.Two.ordinal() == position) {
                return new TwoFragment();
            } else if (PageInfo.Three.ordinal() == position) {
                return new ThreeFragment();
            }
            return null;
        }//end method

        @Override
        public int getCount() {
            return PageInfo.values().length;
        }//end method

        @Override
        public CharSequence getPageTitle(int position) {
            return Test.this.getString(PageInfo.values()[position].titleResId);
        }//end method
    }//end inner class
}//end class

我的PreferenceFragment(简化):

public class OneFragment extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setPreferenceScreen(create());
    }//end method

    private PreferenceScreen create(){
        PreferenceScreen root = getPreferenceManager().createPreferenceScreen(context);

        CheckBoxPreference backup = new CheckBoxPreference(context);
        backup.setKey(Data.BACKUP_ENABLED);
        root.addPreference(backup); 

        return root;
    }//end method   
}//end class

主.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/titles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/abs__background_holo_dark"
        app:footerIndicatorStyle="triangle" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"
        android:scrollbarAlwaysDrawVerticalTrack="true" />

</LinearLayout>
4

1 回答 1

0

嗯,想通了……费了不少功夫。

我正在使用这个解决方案:http: //forum.xda-developers.com/showthread.php? t=1363906 对其进行了大量修改以供我使用(自定义首选项)并使其与 HoloEveryWhere 一起使用

解决方案现在看起来像这样:

import xxx.xxx.android.preferences.PreferenceFragmentCompat;

import org.holoeverywhere.app.Activity;
import org.holoeverywhere.app.Fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle;

public class Test extends Activity {

    private PreferenceScreensData data;
    private ViewPager Pager;

    enum PageInfo {
        One(R.string.one), Two(R.string.two), Three(R.string.three);
        int titleResId;

        PageInfo(int titleResId) {
            this.titleResId = titleResId;
        }
    }

    public void onCreate(Bundle b) {
        super.onCreate(b);

        setContentView(R.layout.main);

        Pager = (ViewPager) findViewById(R.id.pager);
        Pager.setAdapter(new PagerAdapter(getSupportFragmentManager(), this));
        TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
        titleIndicator.setViewPager(Pager);
        titleIndicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
        Pager.setCurrentItem(0);
    }// end method

    class PagerAdapter extends FragmentPagerAdapter {

        PreferenceFragmentCompat[] fragments;
        String[] titles;

        public PagerAdapter(FragmentManager fm, Context context) {
            super(fm);

            data            = new PreferenceScreensData(context);                   
            fragments       = new PreferenceFragmentCompat[3];
            fragments[0]    = new PreferenceFragmentCompat(context, data.getPreferenceScreenOne());         
            fragments[1]    = new PreferenceFragmentCompat(context, data.getPreferenceScreenTwo());
            fragments[2]    = new PreferenceFragmentCompat(context, data.getPreferenceScreenThree());

            titles      = new String[3];
            titles[0]   = context.getString(R.string.one);
            titles[1]   = context.getString(R.string.two);
            titles[2]   = context.getString(R.string.three);
        }//end constructor

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }//end method

        @Override
        public int getCount() {
            return fragments.length;
        }//end method

        @Override
        public CharSequence getPageTitle(int position) {
            return Test.this.getString(PageInfo.values()[position].titleResId);
        }// end method
    }// end inner class
}//end class
于 2013-02-08T10:21:40.830 回答