MainActivity.java
当我像这样启动Fragment时,它会显示出来.例如:
LaunchListFragment fragment = new LaunchListFragment();fragment.newInstance(List_TYPE);getSupportFragmentManager().beginTransaction() .add(R.ID.item_detail_container,fragment).commit();
我在上面的代码中尝试了这个更改以使用VIEwPager,如下所示:
mVIEwPager = (VIEwPager) findVIEwByID(R.ID.pager);mVIEwPager.setAdapter(new LaunchPageAdapter(getSupportFragmentManager(),List_TYPE));mVIEwPager.setCurrentItem(0);
其中LaunchPageAdapter调用LaunchListFragment.
LaunchPageAdapter.java
public class LaunchPageAdapter extends FragmentPagerAdapter {private static String select=""; public LaunchPageAdapter(FragmentManager fm,String type) { super(fm); select=type; } @OverrIDe public Fragment getItem(int position) { switch (position) { case 0: return LaunchListFragment.newInstance(select); case 1: return AddTeamFragment.newInstance(); } return null; } @OverrIDe public int getCount() { // Todo auto-generated method stub return 2; }
这是LaunchListFragment.java
public class LaunchListFragment extends ListFragment implements Actionbar.TabListener {public static String List_TYPE = "invalID";GenericListData g_data[] = null; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw result = inflater.inflate(R.layout.fragment_launch_List,container,false); setActionTabs(); setList(); return (result); } public static Fragment newInstance(String type) { Fragment frag = new LaunchListFragment(); Bundle args = new Bundle(); List_TYPE=type; args.putString(List_TYPE,type); frag.setArguments(args); return (frag);}
这是MainActivity使用的main.xml布局
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools= "match_parent"androID:layout_height="match_parent"androID:layout_marginleft="16dp"androID:layout_marginRight="16dp"androID:baselineAligned="false"androID:divIDer="?androID:attr/divIDerHorizontal"androID:orIEntation="horizontal"androID:showdivIDers="mIDdle"tools:context=".MainActivity" ><fragment androID:ID="@+ID/item_List" androID:name="com.teammanager.ItemListFragment" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" tools:layout="@androID:layout/List_content" /><FrameLayout androID:ID="@+ID/item_detail_container" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="3" > <androID.support.v4.vIEw.VIEwPager androID:ID="@+ID/pager" androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" /></FrameLayout>
LaunchListFragment使用的fragment_launch_List.xml
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:orIEntation="vertical" ><ListVIEw androID:ID="@androID:ID/List" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_weight="1" androID:drawSelectorOntop="false" ></ListVIEw><TextVIEw androID:ID="@+ID/itemname" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_alignParentBottom="true" androID:layout_alignParenttop="true" androID:layout_marginBottom="5dp" androID:layout_margintop="5dp" androID:gravity="center_vertical" androID:textcolor="#000000" androID:textSize="22dp" androID:textStyle="bold" />
当我调试它时,我可以看到LaunchListFragment正在实例化,onCreate和onCreate VIEw被调用,它不会被显示. 总结
以上是内存溢出为你收集整理的android – ViewPager显示碎片的麻烦全部内容,希望文章能够帮你解决android – ViewPager显示碎片的麻烦所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)