我有3个标签,3个与标签相关联的列表视图片段,其中2个正在处理第1个和第3个,但是如果我将其位置设置为0,则中间的一个没有显示并且它不是空的b / c ,它会显示..这很奇怪...我想知道是否有人经历过这个以及它的android bug ...给我一些建议。感谢。
以下是一些代码:
这是活动布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/assign"
android:layout_height="match_parent">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/navbar_layout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabspager"
android:layout_width="match_parent"
app:tabTextColor="@color/colorPrimaryDark"
android:layout_height="460dp">
</android.support.v4.view.ViewPager>
</RelativeLayout>
这是主要活动:
public class main_activity extends AppCompatActivity implements
android.support.v7.app.ActionBar.TabListener{
private ViewPager tabsviewPager;
private ActionBar mActionBar;
private TabsAdapter mTabsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
tabsviewPager = (ViewPager) findViewById(R.id.tabspager);
mTabsAdapter = new TabsAdapter(getSupportFragmentManager());
tabsviewPager.setAdapter(mTabsAdapter);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab onestab =
getSupportActionBar().newTab().setText("one").setTabListener(this);
ActionBar.Tab twotab =
getSupportActionBar().newTab().setText("two").setTabListener(this);
ActionBar.Tab threetab =
getSupportActionBar().newTab().setText("three").setTabListener(this);
getSupportActionBar().addTab(onestab);
getSupportActionBar().addTab(twotab);
getSupportActionBar().addTab(threetab);
//This helps in providing swiping effect for v7 compat library
tabsviewPager.setOnPageChangeListener(new
ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
getSupportActionBar().setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onTabReselected(ActionBar.Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(ActionBar.Tab selectedtab,
FragmentTransaction arg1) {
// TODO Auto-generated method stub
tabsviewPager.setCurrentItem(selectedtab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
这是标签适配器:
public class TabsAdapter extends FragmentStatePagerAdapter {
private int TOTAL_TABS = 3;
public TabsAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int index) {
// TODO Auto-generated method stub
switch (index) {
case 0:
return new oneFragment();
case 1:
return new twoFragment();
case 2:
return new threeFragment();
}
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return TOTAL_TABS;
}
}
这是我设置它的片段,以便它可以在选择时显示列表视图:
public class twoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.two_parent, container, false);
ListView View = (ListView) view.findViewById(R.id.testingView2);
assignDB assignDB = new assignDB(getContext());
List<TWO> assignData = assignDB.getAll();
two_adapter adapter = new two_adapter(getContext(), assignData);
View.setAdapter(adapter);
return view;
}
}