左边ListView+右边framlayout占位

public class Fragment02 extends Fragment{
    private ListView lv;
    private FrameLayout framlayout;
    private List<String> list;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment02,container,false);
        lv=view.findViewById(R.id.lv);
        framlayout=view.findViewById(R.id.framlayout);
        list=new ArrayList<String>();

        list.add("头条");
        list.add("社会");
        list.add("国内");
        list.add("国际");
        list.add("娱乐");
        list.add("体育");
        list.add("军事");
        list.add("科技");
        list.add("财经");
        list.add("时尚");
        lv.setAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,list));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){

                    case 0:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_toutiao()).commit();
                        break;
                    case 1:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_shehui()).commit();
                        break;
                    case 2:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_guoji()).commit();
                        break;
                    case 3:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_guoji2()).commit();
                        break;
                    case 4:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_yule()).commit();
                        break;
                    case 5:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_tiyu()).commit();
                        break;
                    case 6:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_junshi()).commit();
                        break;
                    case 7:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_keji()).commit();
                        break;
                    case 8:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_caijing()).commit();
                        break;
                    case 9:
                        getChildFragmentManager().beginTransaction().replace(R.id.framlayout,new Fragment_shishang()).commit();
                        break;
                }
            }
        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值