Android中,http请求数据进行数据更新功能

HttpUtil.sendOKHttpRequest(url, new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {
        Log.d(TAG, "请求泥头接口失败!" );
    }
    @Override
    public void onResponse(Call call, Response response) throws IOException {
        //将数据存放到下拉菜单中
        String res = response.body().string();
        Log.d(TAG,"请求泥头返回信息:"+res);
        /* Gson gson = new Gson();*/
        List siteList = new ArrayList();
        if (!TextUtils.isEmpty(res)){//不为空时直接赋值
            try {
                JSONArray allSites = new JSONArray(res);
                for (int i=0;ifinal ArrayAdapter  adapterSiteStart = new ArrayAdapter(getActivity() , android.R.layout.simple_spinner_item , siteList);
        getActivity().runOnUiThread(new Runnable() {//在fragment中修改页面的数据要添加的部分
            @Override
            public void run() {
                startSiteSpinner.setAdapter(adapterSiteStart);
            }
        });

    }
});

你可能感兴趣的:(Java,andriod)