package com.example.week2.view.view.view.view.view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import com.example.week2.R;
import com.example.week2.view.view.view.view.adapter.MyRecListAdapter;
import com.example.week2.view.view.view.view.model.RecBean;
import com.example.week2.view.view.view.view.util.OkHttp3Util;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class Shopp extends AppCompatActivity {
private CheckBox lieq;
private EditText lshu;
private Button ssou;
private RecyclerView srecyc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopp);
lieq = (CheckBox) findViewById(R.id.lieq);
lshu = (EditText) findViewById(R.id.lshu);
ssou = (Button) findViewById(R.id.ssou);
srecyc = (RecyclerView) findViewById(R.id.srecyc);
getchu();
}
public void getchu(){
ssou.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sou = lshu.getText().toString();
if(TextUtils.isEmpty(sou)){
}else {
OkHttp3Util.doGet("https://www.zhaoapi.cn/product/searchProducts?keywords=笔记本&page=1", new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if(response.isSuccessful()){
final String json = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
RecBean recBean = new Gson().fromJson(json, RecBean.class);
List<RecBean.DataBean> data = recBean.getData();
List<String> listi = new ArrayList<String>();
for(int i=0;i<data.size();i++){
String images = data.get(i).getImages();
listi.add(images);
}
MyRecListAdapter mli = new MyRecListAdapter(Shopp.this,data);
srecyc.setAdapter(mli);
srecyc.setLayoutManager(new LinearLayoutManager(Shopp.this,LinearLayoutManager.VERTICAL,false));
}
});
}
}
});
}
}
});
}
}
RecyclerView的应用
最新推荐文章于 2020-12-02 15:38:53 发布