当我滑过最后一个标签时,Holoeverywhere标签加载第一个标签?

时间:2013-05-05 13:46:43

标签: android actionbarsherlock android-holo-everywhere actionbarsherlock-map

最近,我正在使用holoeverywhere做某事,但现在我遇到一个问题,当我在到达最后一个标签后继续向右滑动时,程序将加载第一个标签的视图,但没有更多标签,所以程序会崩溃。问题描述如下,我真的需要有人来帮助我。 谢谢大家!

以下是我的代码:

public static class TabFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        TextView textView = new TextView(getSupportActivity());
        textView.setText("Position: " + getArguments().getInt("position"));
        return textView;
    }
}

 private static Bundle make(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("position", i);
        return bundle;
    }

@Override
protected void onHandleTabs() {
    getSupportActionBar().removeAllTabs();
    for(int i = 0; i < 5; i++)
        addTab("Tab #" + i, TabFragment.class, make(i + 1));
}

问题是当我在最后一个标签之后滑动时,视图会是这样的:

enter image description here

并且程序将崩溃并出现以下错误:

05-05 21:33:26.258: E/AndroidRuntime(1573): FATAL EXCEPTION: main
05-05 21:33:26.258: E/AndroidRuntime(1573): java.lang.IndexOutOfBoundsException: Invalid index 5, size is 5
05-05 21:33:26.258: E/AndroidRuntime(1573):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at java.util.ArrayList.get(ArrayList.java:304)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.app.ActionBarImpl.getTabAt(ActionBarImpl.java:989)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.actionbarsherlock.internal.app.ActionBarWrapper.getTabAt(ActionBarWrapper.java:425)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at org.holoeverywhere.app.TabSwipeActivity.dispatchTabSelected(TabSwipeActivity.java:135)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at org.holoeverywhere.app.TabSwipeActivity.access$2(TabSwipeActivity.java:128)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at org.holoeverywhere.app.TabSwipeActivity$TabSwipeAdapter.onPageSelected(TabSwipeActivity.java:67)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:538)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:1943)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.View.dispatchTouchEvent(View.java:5486)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1714)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1959)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1728)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1892)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1840)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.View.dispatchPointerEvent(View.java:5662)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2863)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.os.Looper.loop(Looper.java:137)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at android.app.ActivityThread.main(ActivityThread.java:4340)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at java.lang.reflect.Method.invokeNative(Native Method)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at java.lang.reflect.Method.invoke(Method.java:511)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-05 21:33:26.258: E/AndroidRuntime(1573):     at dalvik.system.NativeStart.main(Native Method)

我还使用了一些自定义设置:

getSupportActionBar().setCustomView(getLayoutInflater().inflate(R.layout.****,null));
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home : R.id.abs__home);
((View) homeIcon.getParent()).setVisibility(View.GONE);

和此:

getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setDisplayShowCustomEnabled(true);

以下是演示代码,我只是不明白。在演示中,当我到达最后一个标签后,当我从右到右时,程序将在屏幕的右侧显示如下内容:

enter image description here

这些是演示代码:

public static class TabFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        Log.d("DemoTabsActivity", "test" + getArguments().getInt("position"));
        TextView textView = new TextView(getSupportActivity());
        textView.setText("Position: " + getArguments().getInt("position"));
        return textView;
    }
}

private static Bundle make(int i) {
    Bundle bundle = new Bundle();
    bundle.putInt("position", i);
    return bundle;
}

@Override
protected void onHandleTabs() {
    getSupportActionBar().removeAllTabs();
    for(int i = 0; i < 10; i++)
        addTab("Tab #" + i, TabFragment.class, make(i + 1));
    Log.d("TAG", "getSupportActionBar().getTabCount()" + getSupportActionBar().getTabCount());
}

1 个答案:

答案 0 :(得分:0)

java.lang.IndexOutOfBoundsException: Invalid index 5, size is 5

在代码中的某处,您尝试访问/修改只有四个元素的数组的第五个元素。