私はこの問題で立ち往生しています。さまざまなアプリのswipe
間に挿入しようとしています。fragments
スワイプ自体は完全に機能しますが、問題は、さまざまなフラグメントで定義したアクションがさまざまなものによって認識されないことです。toggle / buttons
つまり、さまざまな間をスワイプするだけ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
う!現時点では、さまざまなトグルとボタンのすべてに、認識されない定義済みの機能があります
public class PerformanceActivity extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.performance, container, false);
//blablabla all my buttons and toggles (THAT WORKS BEFORE THE IMPLEMENTATION OF THE SWIPE)
return v;
}
助けてくれてありがとう :)