多条目Fragment

public class HomeFragment extends Fragment implements IContract.IView {

private XRecyclerView rv;
private IProAdapter iProAdapter;
private Ipresenter ipresenter;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.homefragment,container,false);
    return view;
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //获取资源id
    rv=view.findViewById(R.id.rv);
    //布局管理器
    rv.setLayoutManager(new LinearLayoutManager(getActivity()));

    //创建P层,实例化
    ipresenter = new Ipresenter(this);
    ipresenter.showpost(Api.PATH,new HashMap());
}



@Override
public void onSuccess(IBean.DataBean data) {
if (data!=null){
    //创建适配器
    iProAdapter = new IProAdapter(getActivity());
    //设置适配器
    rv.setAdapter(iProAdapter);
    iProAdapter.setlist(data);
}
}

@Override
public void onFailure(String msg) {
    Toast.makeText(getActivity(),msg,Toast.LENGTH_SHORT).show();
}

//销毁页面
@Override
public void onDestroy() {
    super.onDestroy();
    if (ipresenter!=null){
        ipresenter.setcancle();
    }
}

}

你可能感兴趣的:(多条目Fragment)