码迷,mamicode.com
首页 > 其他好文 > 详细

Retrofit

时间:2018-05-03 19:34:53      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:get   bsp   vertica   content   toast   array   tco   .data   back   

  private OkHttpClient mOkHttpClient;
    private RecyclerView mRecycle_View;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        mOkHttpClient = new OkHttpClient.Builder().build();

        init();
    }
    private void initView() {

        mRecycle_View = (RecyclerView) findViewById(R.id.mRecycle_View);

    }

    private void init() {

        new Retrofit.Builder()
                .baseUrl("http://www.qubaobei.com/")
                .client(mOkHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(HttpCall.class)
                .getHttpBean_mainCall(1,20,1)
                .enqueue(new Callback<Bean>() {
                    @Override
                    public void onResponse(Call<Bean> call, Response<Bean> response) {
                        ArrayList<Bean.DataBean> data = (ArrayList<Bean.DataBean>)
                                response.body().getData();
                        MyAdapter adapter = new MyAdapter(data, MainActivity.this);
                        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
                        mRecycle_View.setAdapter(adapter);
                        mRecycle_View.setLayoutManager(layoutManager);

                    }

                    @Override
                    public void onFailure(Call<Bean> call, Throwable t) {
                        Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT).show();
                    }
                });

 

Retrofit

标签:get   bsp   vertica   content   toast   array   tco   .data   back   

原文地址:https://www.cnblogs.com/98k98k/p/8986423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!