美文网首页
Xutils 和 Okhttp调用notifyDataSetCh

Xutils 和 Okhttp调用notifyDataSetCh

作者: 扯淡的青春丶过客 | 来源:发表于2017-11-14 09:15 被阅读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();

        };

    };

    相关文章

      网友评论

          本文标题:Xutils 和 Okhttp调用notifyDataSetCh

          本文链接:https://www.haomeiwen.com/subject/qulxvxtx.html