Xutils 和 Okhttp调用notifyDataSetCh

2017-11-14  本文已影响0人  扯淡的青春丶过客

在Xutils中 可直接在onSuccess方法中调用 myAdapter.notifyDataSetChanged();通知适配器发生改变

okhttp中 不能在onResponse方法中直接调用

okHttpClient.newCall(request).enqueue(new okhttp3.Callback() {

    @Override

    public void onFailure(Call call, IOException e) {

        Log.e("test", e.getMessage());

    }

    @Override

    public void onResponse(Call call, Response response) throws IOException {

        Message msg = new Message();

        handler.sendMessage(msg);

    }

});

private Handler handler = new Handler() {

    public void handleMessage(Message msg) {

    myAdapter.notifyDataSetChanged();

    };

};

上一篇下一篇

猜你喜欢

热点阅读