我想创建2个标签(Tab1,Tab2) 但是在tab1中我想要滑动 点击(tab1) Frag1.1 - > Frag1.2 - > Frag1.3 点击(tab2) Frag2.1 - > Frag2.2 - > Frag2.3
我该怎么做?我找不到任何关于这个标签+滑动的教程。你能帮助我吗?
我应该获得2个片段适配器吗? 我正在尝试使用2个片段适配器并设置为这样,但是我收到错误“片段当前不在片段管理器中”。
有什么想法吗?
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public Context context;
public MyTabsListener(Fragment fragment, Context context) {
this.fragment = fragment;
this.context = context;
}
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
Toast.makeText(context, "Reselected!", Toast.LENGTH_SHORT).show();
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
Toast.makeText(context, "Selected!", Toast.LENGTH_SHORT).show();
if(tab.getPosition() == 0)
{
/** Setting the pagerAdapter to the pager object */
pager.setAdapter(pagerAdapter);
//ft.replace(R.id.fragment_container, fragment);
}
else
{
/** Setting the pagerAdapter to the pager object */
pager.setAdapter(pagerAdapter2);
}
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
Toast.makeText(context, "Unselected!", Toast.LENGTH_SHORT).show();
ft.remove(fragment);
}
}
答案 0 :(得分:1)