HoloEveryWhere: ViewPagerIndicator с PreferenceFragment, ошибка надувания класса <unknown>

Я использую 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

main.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>

1 ответ

Решение

Ну разобрался... потребовалось много работы.

Я использую это решение: 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
Другие вопросы по тегам