Я создаю noob для Android, и у меня есть проблема с отображением экрана предпочтений в viewpager. В настоящее время мое приложение показывает, что все страницы пульта просмотра перепутаны как одна страница с экраном предпочтений, служащим фоном. Затем, когда я жестом, приложение вылетает из-за исключения InflateException. Я исследовал потенциальные причины с вопросами SO здесь и здесь, но ни один из них не предлагает решения, которые исправляют мою проблему. Я бы просто использовал фрагмент Preference, но я разрабатываю для min 8 API. Любая помощь приветствуется.
МОЙ КОД
public class Options extends PreferenceActivity implements OnClickListener ,SharedPreferences.OnSharedPreferenceChangeListener{
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
View view;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
mSherlock.setContentView(R.layout.options);
MyPagerAdapter adapter = new MyPagerAdapter(this);
ViewPager myPager = (ViewPager) findViewById(R.id.viewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(2);
TitlePageIndicator indicator = (TitlePageIndicator)findViewById( R.id.indicator );
indicator.setViewPager( myPager );
indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if(position == 0 ||position == 1||position == 2||position == 4){
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
private class MyPagerAdapter extends PagerAdapter {
private String[] titles = new String[] {"HELP", "PREFERENCES", "ABOUT" };
private final Context context;
private int[] scrollPosition = new int[titles.length];
public MyPagerAdapter( Context context )
{
this.context = context;
for ( int i = 0; i < titles.length; i++ )
{
scrollPosition[i] = 0;
}
}
@Override
public String getPageTitle( int position )
{
return titles[position];
}
@Override
public int getCount()
{
return titles.length;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 2:
resId = R.layout.help;
view = inflater.inflate(resId, null);
LinearLayout layout0=(LinearLayout)view.findViewById(R.id.helplayout);
((ViewPager) collection).addView(view, 0);
return view;
case 0:
resId = R.xml.prefs;
view = inflater.inflate(resId, null);
LinearLayout layout1=(LinearLayout)view.findViewById(R.id.RLcoins);
((ViewPager) collection).addView(view, 0);
return view;
case 1:
resId = R.layout.about;
view = inflater.inflate(resId, null);
LinearLayout layout2=(LinearLayout)view.findViewById(R.id.LLtwitter);
((ViewPager) collection).addView(view, 0);
return view;
}
return resId;
}
MY LOGCAT
11-27 16:00:50.039: E/AndroidRuntime(3993): FATAL EXCEPTION: main
11-27 16:00:50.039: E/AndroidRuntime(3993): android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-27 16:00:50.039: E/AndroidRuntime(3993): at com.bryanjrichardson.GSCC.Options$MyPagerAdapter.instantiateItem(Options.java:130)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:692)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.ViewPager.populate(ViewPager.java:849)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.ViewPager.populate(ViewPager.java:772)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1539)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1422)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.drawChild(ViewGroup.java:1562)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.View.draw(View.java:6883)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-27 16:00:50.039: E/AndroidRuntime(3993): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2116)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewRoot.draw(ViewRoot.java:1565)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewRoot.performTraversals(ViewRoot.java:1301)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.ViewRoot.handleMessage(ViewRoot.java:1914)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.os.Looper.loop(Looper.java:130)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.app.ActivityThread.main(ActivityThread.java:3859)
11-27 16:00:50.039: E/AndroidRuntime(3993): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 16:00:50.039: E/AndroidRuntime(3993): at java.lang.reflect.Method.invoke(Method.java:507)
11-27 16:00:50.039: E/AndroidRuntime(3993): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-27 16:00:50.039: E/AndroidRuntime(3993): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-27 16:00:50.039: E/AndroidRuntime(3993): at dalvik.system.NativeStart.main(Native Method)
11-27 16:00:50.039: E/AndroidRuntime(3993): Caused by: java.lang.ClassNotFoundException: android.view.PreferenceScreen in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.bryan.GSCC-1.apk]
11-27 16:00:50.039: E/AndroidRuntime(3993): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-27 16:00:50.039: E/AndroidRuntime(3993): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-27 16:00:50.039: E/AndroidRuntime(3993): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
11-27 16:00:50.039: E/AndroidRuntime(3993): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-27 16:00:50.039: E/AndroidRuntime(3993): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)