烂牌大师9527 2017-08-25 02:20 采纳率: 92.9%
浏览 1096
已采纳

重金悬赏,求解为何运行app,加载失败,我的address哪里错了,去郭霖网站注册了一个key怎么用

package com.coolweather.app.activity;

import java.util.ArrayList;
import java.util.List;
import com.coolweather.app.R;
import com.coolweather.app.db.CoolWeatherDB;
import com.coolweather.app.model.City;
import com.coolweather.app.model.County;
import com.coolweather.app.model.Province;
import com.coolweather.app.util.HttpCallbackListener;
import com.coolweather.app.util.HttpUtil;
import com.coolweather.app.util.Utility;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ChooseAreaActivity extends Activity{
public static final int LEVEL_PROVINCE=0;
public static final int LEVEL_CITY=1;
public static final int LEVEL_COUNTY=2;
private ProgressDialog progressDialog;
private TextView titleText;
private ListView listView;
private ArrayAdapter adapter;
private CoolWeatherDB coolWeatherDB;
private List dataList=new ArrayList();
private List provinceList;
private List cityList;
private List countyList;
private Province selectedProvince;
private City selectedCity;
private int currentLevel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.choose_area);
titleText=(TextView)findViewById(R.id.title_text);
listView=(ListView)findViewById(R.id.list_view);
adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,dataList);
listView.setAdapter(adapter);
coolWeatherDB=CoolWeatherDB.getInstance(this);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?>arg0,View view, int index,long arg3) {
if(currentLevel==LEVEL_PROVINCE) {
selectedProvince=provinceList.get(index);
queryCities();
}else if(currentLevel==LEVEL_CITY) {
selectedCity=cityList.get(index);
queryCounties();
}
}

        });
        queryProvinces();
    }
    private void queryProvinces() {
        // TODO Auto-generated method stub
        provinceList=coolWeatherDB.loadProvinces();
        if(provinceList.size()>0) {
            dataList.clear();
            for(Province province:provinceList) {
                dataList.add(province.getProvinceName());

            }
            adapter.notifyDataSetChanged();
            listView.setSelection(0);
            titleText.setText("中国");
            currentLevel=LEVEL_PROVINCE;

        }else {
            String address="http://guolin.tech/api/china";
            queryFromServer(address,"province");
        }
    }


        private void queryCities() {
            cityList=coolWeatherDB.loadCities(selectedProvince.getId());
            if(cityList.size()>0) {
                dataList.clear();
                for(City city:cityList) {
                    dataList.add(city.getCityName());

                }
                adapter.notifyDataSetChanged();
                listView.setSelection(0);
                titleText.setText(selectedProvince.getProvinceName());
                currentLevel=LEVEL_CITY;
            }else {
                int provinceCode=selectedProvince.getProvinceCode();
                String address="http://guolin.tech/api/china/"+provinceCode;
                queryFromServer(address,"city");
            }
        }
        private void queryCounties() {
            // TODO Auto-generated method stub
            countyList=coolWeatherDB.loadCounties(selectedCity.getId());
            if(countyList.size()>0) {
                dataList.clear();
                for(County county:countyList) {
                    dataList.add(county.getCountyName());
                }
                adapter.notifyDataSetChanged();
                listView.setSelection(0);
                titleText.setText(selectedCity.getCityName());
                currentLevel=LEVEL_COUNTY;

            }else {
                int provinceCode=selectedProvince.getProvinceCode();
                int cityCode=selectedCity.getCityCode();
                String address="http://guolin.texh/api/china/"+provinceCode+"/"+cityCode;
                queryFromServer(address,"county");
            }
        }


    private void queryFromServer(String address,final String type) {
        // TODO Auto-generated method stub
        showProgressDialog();
        HttpUtil.sendHttpRequest(address,new HttpCallbackListener() {
            @Override
            public void onFinish(String  response) {
                boolean result=false;
                if("province".equals(type)) {
                    result=Utility.handleProvinceResponse(coolWeatherDB, response);
                }else if("city".equals(type)){
                    result=Utility.handleCityResponse(coolWeatherDB, response,selectedProvince.getId());
                }else if("county".equals(type)) {
                    result=Utility.handleCountyResponse(coolWeatherDB, response,selectedCity.getId());
                }
                if(result) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            closeProgressDialog();
                            if("province".equals(type)) {
                                queryProvinces();
                            }else if("city".equals(type)) {
                                queryCities();
                            }else if("county".equals(type)) {
                                queryCounties();
                            }
                        }
                    });
                }
            }
            @Override
            public void onError(Exception e) {
                runOnUiThread(new Runnable(){
                    @Override
                    public void run() {
                        closeProgressDialog();
                        Toast.makeText(ChooseAreaActivity.this,"加载失败", Toast.LENGTH_LONG).show();
                    }
                });
            }
        });
    }
    private void showProgressDialog() {
        // TODO Auto-generated method stub
        if(progressDialog==null) {
            progressDialog=new ProgressDialog(this);
            progressDialog.setMessage("正在加载");
            progressDialog.setCanceledOnTouchOutside(false);

        }
        progressDialog.show();
    }
    private void closeProgressDialog() {
    if(progressDialog!=null) {
        progressDialog.dismiss();
    }
    }
    @Override
    public void onBackPressed() {
        if(currentLevel==LEVEL_COUNTY) {
            queryCities();
        }else if(currentLevel==LEVEL_CITY) {
            queryProvinces();
        }else {
            finish();
        }
    }

}

  • 写回答

4条回答

  • 烂牌大师9527 2017-08-25 02:23
    关注

    大神们在不在,给个修改建议

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题