0
最近,我使用holoeverywhere做某事,但現在我面臨的一個問題是,當我在到達最後一個選項卡後繼續滑動時,程序將加載第一個選項卡的視圖,但沒有更多選項卡,因此程序會崩潰。問題描述如下,我真的需要有人來幫助我。 感謝大家!當我滑過最後一個標籤時,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));
}
的問題是,當我最後一個標籤後滑動,認爲會是這樣的:
,程序將崩潰出現以下錯誤:
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)
我還用som Ë自定義設置:
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);
以下是演示的代碼,我只是不明白。在演示中,當我到達最後一個選項卡後,一邊向右側,程序將展示一些東西在屏幕的右側是這樣的:
,這些都是演示代碼:
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());
}
我更新了上面的演示代碼,我很難找到差異。 – 2013-05-05 13:59:05
錯誤和問題保持不變,所以至少你現在知道在哪裏查找錯誤 – 2013-05-05 14:02:06
看起來並不那麼容易 – 2013-05-05 14:06:47