new Thread(new Runnable() {
@Override
public void run() {
OkhttpUtils okhttpUtils = new OkhttpUtils(BaseApplication.getInstance());
okhttpUtils.getProductInfo(new OkhttpCallback() {
@Override
public void onError(Exception e) {
LogUtils.e("get product " + e.toString());
handler.sendEmptyMessage(AppConstants.DATA_LOAD_FAILED);
}
@Override
public void onSuccess(int productNum, String result, List<String> title, List<String> url) {
LogUtils.d("get product success");
productInfoList.clear();
for (int i = 0; i < productNum; i++) {
ProductInfo productInfo = new ProductInfo(title.get(i), url.get(i));
Log.d("onSuccess", title.get(i) + " " + url.get(i));
productInfoList.add(productInfo);
}
Message message = new Message();
message.what = AppConstants.DATA_LOAD_OK;
handler.sendMessage(message);
SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swipeRefreshlayout);
swipeRefreshLayout.setRefreshing(false);
}
});
}
}).start();
项目网络请求时使用的代码
最新推荐文章于 2024-05-16 17:27:28 发布