Android:TabListener,Swipe和制表符片段

时间:2013-01-25 00:40:36

标签: android eclipse android-activity android-actionbar swipe

我遇到了这个问题。我正在尝试在我的应用的各种swipe之间插入fragments。滑动本身工作完美,但问题,我不明白为什么,我在各种片段中定义的动作不被各种toggle / buttons等识别。换句话说,它只是在各种{之间滑动{1}}。 这是我的代码(删除了不必要的部分)

layouts

这是我的主要活动,如您所见,标签设置正确。 举个例子public class MainActivity extends FragmentActivity implements ActionBar.TabListener { CollectionPagerAdapter mCollectionPagerAdapter; ViewPager mViewPager; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); { Runtime runtime = Runtime.getRuntime(); try { runtime.exec("su"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } mCollectionPagerAdapter = new CollectionPagerAdapter( getSupportFragmentManager()); final ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mCollectionPagerAdapter); mViewPager .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); for (int i = 0; i < mCollectionPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() .setText(mCollectionPagerAdapter.getPageTitle(i)) .setTabListener(this)); } } public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { mViewPager.setCurrentItem(tab.getPosition()); } public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { } public class CollectionPagerAdapter extends FragmentPagerAdapter { final int NUM_ITEMS = 10; // number of tabs public CollectionPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { Fragment fragment = new TabFragment(); Bundle args = new Bundle(); args.putInt(TabFragment.ARG_OBJECT, i); fragment.setArguments(args); return fragment; } @Override public int getCount() { return NUM_ITEMS; } @Override public CharSequence getPageTitle(int position) { String tabLabel = null; switch (position) { case 0: tabLabel = getString(R.string.tabWelcome); break; case 1: tabLabel = getString(R.string.tabPerformance); break; case 2: tabLabel = getString(R.string.tabBattery); break; case 3: tabLabel = getString(R.string.tabNetwork); break; case 4: tabLabel = getString(R.string.tabImages); break; case 5: tabLabel = getString(R.string.tabAudio); break; case 6: tabLabel = getString(R.string.tabGps); break; case 7: tabLabel = getString(R.string.tabKernel); break; case 8: tabLabel = getString(R.string.tabMisc); break; case 9: tabLabel = getString(R.string.tabTools); break; } return tabLabel; } } public static class TabFragment extends Fragment { public static final String ARG_OBJECT = "object"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments(); int position = args.getInt(ARG_OBJECT); int tabLayout = 0; switch (position) { case 0: tabLayout = R.layout.welcome; break; case 1: tabLayout = R.layout.performance; break; case 2: tabLayout = R.layout.battery; break; case 3: tabLayout = R.layout.network; break; case 4: tabLayout = R.layout.images; break; case 5: tabLayout = R.layout.audio; break; case 6: tabLayout = R.layout.gps; break; case 7: tabLayout = R.layout.kernel; break; case 8: tabLayout = R.layout.misc; break; case 9: tabLayout = R.layout.tools; break; } View rootView = inflater.inflate(tabLayout, container, false); return rootView; } } } ! 目前,所有各种切换和按钮都有一个无法识别的定义功能

Performance.java

感谢您的帮助:)

0 个答案:

没有答案