如图所示,求大佬解答!
1条回答 默认 最新
- qq_40967081 2021-04-14 20:38关注
package net.mwplay.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.util.LogUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import net.mwplay.adapter.HomeAdapter;
import net.mwplay.bean.TieBean;
import net.mwplay.bslm.R;
import java.util.ArrayList;
import java.util.List;
/**
* Created by tian on 15/5/18.
*/
public class HomeFragment extends Fragment{
@ViewInject(R.id.viewPager)
ViewPager mViewPager;
ViewPagerAdapter adapter;
int NUMS = 5;
String [] tabs = {"1", "2", "3", "4", "5"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
ViewUtils.inject(this, v);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new ViewPagerAdapter(getChildFragmentManager());//最关键的地方是这里
mViewPager.setAdapter(adapter);
}
public class ViewPagerAdapter extends FragmentPagerAdapter{
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return new TabFragment();
}
@Override
public int getCount() {
return NUMS;
}
}
}
最关键的地方在于传入 getChildFragmentManager本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥50 adb连接不到手机是怎么回事?
- ¥15 vs2022无法联网
- ¥15 TCP的客户端和服务器的互联
- ¥15 VB.NET操作免驱摄像头
- ¥15 笔记本上移动热点开关状态查询
- ¥85 类鸟群Boids——仿真鸟群避障的相关问题
- ¥15 CFEDEM自带算例错误,如何解决?
- ¥15 有没有会使用flac3d软件的家人
- ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
- ¥15 docker实践项目