亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

FragmentPagerAdapter

FragmentPagerAdapter

慕粉4089507 2017-06-12 12:22:26
求幫忙看下程序錯在哪,謝謝activity_main<?xml?version="1.0"?encoding="utf-8"?> <RelativeLayout ????xmlns:android="http://schemas.android.com/apk/res/android" ????android:layout_width="match_parent" ????android:layout_height="match_parent"> ????????<android.support.v4.view.ViewPager ????????????android:id="@+id/view_pager" ????????????android:layout_width="match_parent" ????????????android:layout_height="match_parent"> ????????</android.support.v4.view.ViewPager> </RelativeLayout>layout01<?xml?version="1.0"?encoding="utf-8"?> <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android" ??????????????xmlns:app="http://schemas.android.com/apk/res-auto" ??????????????android:orientation="vertical" ??????????????android:layout_width="match_parent" ??????????????android:layout_height="match_parent"> ????<ImageView ????????android:id="@+id/image_view01" ????????android:layout_width="match_parent" ????????android:layout_height="match_parent" ????????android:src="@drawable/a"/> </LinearLayout>layout02<?xml?version="1.0"?encoding="utf-8"?> <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android" ??????????????xmlns:app="http://schemas.android.com/apk/res-auto" ??????????????android:orientation="vertical" ??????????????android:layout_width="match_parent" ??????????????android:layout_height="match_parent"> ????<ImageView ????????android:id="@+id/image_view02" ????????android:layout_width="match_parent" ????????android:layout_height="match_parent" ????????android:src="@drawable/b"/> </LinearLayout>layout03<?xml?version="1.0"?encoding="utf-8"?> <LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android" ??????????????xmlns:app="http://schemas.android.com/apk/res-auto" ??????????????android:orientation="vertical" ??????????????android:layout_width="match_parent" ??????????????android:layout_height="match_parent"> ????<ImageView ????????android:id="@+id/image_view03" ????????android:layout_width="match_parent" ????????android:layout_height="match_parent" ????????android:src="@drawable/c"/> </LinearLayout>Fragment01public?class?Fragment01?extends?Fragment?{ ????@Nullable ????@Override ????public?View?onCreateView(LayoutInflater?inflater,?@Nullable?ViewGroup?container,?@Nullable?Bundle?savedInstanceState)?{ ????????View?view1=inflater.inflate(R.layout.layout01,container,false); ????????return?view1; ????} }Fragment02public?class?Fragment02?extends?Fragment?{ ????@Nullable ????@Override ????public?View?onCreateView(LayoutInflater?inflater,?@Nullable?ViewGroup?container,?@Nullable?Bundle?savedInstanceState)?{ ????????View?view2=inflater.inflate(R.layout.layout02,container,false); ????????return?view2; ????} }Fragment03public?class?Fragment03?extends?Fragment?{ ????@Nullable ????@Override ????public?View?onCreateView(LayoutInflater?inflater,?@Nullable?ViewGroup?container,?@Nullable?Bundle?savedInstanceState)?{ ????????View?view3=inflater.inflate(R.layout.layout03,container,false); ????????return?view3; ????} }MyAdapterpublic?class?MyAdapter?extends?FragmentPagerAdapter?{ ????private?List<Fragment>?fragmentList; ????public?myAdapter(FragmentManager?fm,?List<Fragment>?fragmentList)?{ ????????super(fm); ????????this.fragmentList?=?fragmentList; ????} ????@Override ????public?Fragment?getItem(int?position)?{ ????????return?fragmentList.get(position); ????} ????@Override ????public?int?getCount()?{ ????????return?fragmentList.size(); ????} }MainActivitypublic?class?MainActivity?extends?Activity?{ ????private?List<Fragment>?fragmentList; ????private?ViewPager?viewPager; ????private?Fragment?fragment01,fragment02,fragment03; ????private?myAdapter?myAdapter; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????setContentView(R.layout.activity_main); ????????fragmentList=new?ArrayList<>(); ????????viewPager=(ViewPager)findViewById(R.id.view_pager); ????????fragmentList.add(fragment01); ????????fragmentList.add(fragment02); ????????fragmentList.add(fragment03); ????????myAdapter=new?myAdapter(getSupportFragmentManager(),fragmentList); ????????viewPager.setAdapter(myAdapter); ????} }
查看完整描述

3 回答

已采納
?
蜂之谷

TA貢獻564條經驗 獲得超863個贊

fragment01,fragment02,fragment03 沒有初始化呀

查看完整回答
反對 回復 2017-06-12
  • 3 回答
  • 0 關注
  • 1414 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號