Retrofit
Posted 红领巾传递人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Retrofit相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章