安卓鹏 2016-03-22 01:32 采纳率: 50%
浏览 2011
已采纳

酷欧天气showProgressDialog();代码报错

第一行代码的酷欧天气ChooseAreaActivity,showProgressDialog();总是显示报错,根据原版的代码修改后依然如此,想知道是什么原因。
以下是代码:
package activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.baoyu.coolweather1.R;
import model.City;
import model.CoolWeatherDB;
import model.County;
import model.Province;
import util.HttpCallbackListener;
import util.HttpUtil;
import util.Utility;

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;

  1. private ProgressDialog progressDialog;
  2. private TextView titleText;
  3. private ListView listView;
  4. private ArrayAdapter<String> adapter;
  5. private CoolWeatherDB coolWeatherDB;
  6. private List<String> dataList = new ArrayList<String>();
  7. /*
  8. * 省列表
  9. * */
  10. private List<Province> provinceList;
  11. /*
  12. * 市列表
  13. * */
  14. private List<City> cityList;
  15. /*
  16. * 县列表
  17. * */
  18. private List<County> countyList;
  19. /*
  20. * 选中的省份
  21. * */
  22. private Province selectedProvince;
  23. /*
  24. * 选中的城市
  25. * */
  26. private City selectedCity;
  27. /*
  28. * 当前选中的级别
  29. * */
  30. private int currentLevel;
  31. /*
  32. * 是否从WeatherActivity中跳转过来
  33. * */
  34. private boolean isFromWeatherActivity;
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. isFromWeatherActivity = getIntent().getBooleanExtra("from_weather_activity", false);
  39. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  40. //已经选择了城市且不是从WeatherActivity跳转过来,才会直接转到WeatherActivity
  41. if (prefs.getBoolean("city_selected", false) && !isFromWeatherActivity) {
  42. Intent intent = new Intent(this, WeatherActivity.class);
  43. startActivity(intent);
  44. finish();
  45. return;
  46. }
  47. requestWindowFeature(Window.FEATURE_NO_TITLE);
  48. setContentView(R.layout.choose_area);
  49. listView = (ListView) findViewById(R.id.list_view);
  50. titleText = (TextView) findViewById(R.id.title_text);
  51. adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataList);
  52. listView.setAdapter(adapter);
  53. coolWeatherDB = CoolWeatherDB.getInstance(this);
  54. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  55. @Override
  56. public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) {
  57. if (currentLevel == LEVEL_PROVINCE) {
  58. selectedProvince = provinceList.get(index);
  59. queryCities();
  60. } else if (currentLevel == LEVEL_CITY) {
  61. selectedCity = cityList.get(index);
  62. queryCounties();
  63. } else if (currentLevel == LEVEL_COUNTY) {
  64. String countyCode = countyList.get(index).getCountyCode();
  65. Intent intent = new Intent(ChooseAreaActivity.this, WeatherActivity.class);
  66. intent.putExtra("county_code", countyCode);
  67. startActivity(intent);
  68. finish();
  69. }
  70. }
  71. });
  72. queryProvinces();//加载省级数据
  73. }
  74. /*
  75. * 查询全国所有的省,优先从数据库查询,如果没有查询到再去服务器上查询
  76. * */
  77. private void queryProvinces(){
  78. provinceList = coolWeatherDB.loadProvinces();
  79. if (provinceList.size() > 0) {
  80. dataList.clear();
  81. for (Province province : provinceList) {
  82. dataList.add(province.getProvinceName());
  83. }
  84. adapter.notifyDataSetChanged();
  85. listView.setSelection(0);
  86. titleText.setText("中国");
  87. currentLevel = LEVEL_PROVINCE;
  88. } else {
  89. queryFromServer(null, "province");
  90. }
  91. }
  92. /*
  93. * 查询选中省内所有的市,优先从数据库中查询,如果没有查询到再去服务器上查询
  94. * */
  95. private void queryCities() {
  96. cityList = coolWeatherDB.loadCities(selectedProvince.getId());
  97. if (cityList.size() > 0) {
  98. dataList.clear();
  99. for (City city : cityList) {
  100. dataList.add(city.getCityName());
  101. }
  102. adapter.notifyDataSetChanged();
  103. listView.setSelection(0);
  104. titleText.setText(selectedProvince.getProvinceName());
  105. currentLevel = LEVEL_CITY;
  106. } else {
  107. queryFromServer(selectedProvince.getProvinceCode(), "city");
  108. }
  109. }
  110. /*
  111. * 查询选中市内所有的县,优先从数据库中查询,如果没有查询到再去服务器上查询
  112. * */
  113. private void queryCounties() {
  114. countyList = coolWeatherDB.loadCounties(selectedCity.getId());
  115. if (countyList.size() > 0) {
  116. dataList.clear();
  117. for (County county : countyList) {
  118. dataList.add(county.getCountyName());
  119. }
  120. adapter.notifyDataSetChanged();
  121. listView.setSelection(0);
  122. titleText.setText(selectedCity.getCityName());
  123. currentLevel = LEVEL_COUNTY;
  124. } else {
  125. queryFromServer(selectedCity.getCityCode(), "county");
  126. }
  127. }
  128. /*
  129. *根据传入的代号和类型从服务器上查询省市县数据
  130. * */
  131. private void queryFromServer(final String code, final String type) {
  132. String address;
  133. if (!TextUtils.isEmpty(code)) {
  134. address = "http://www.weather.com.cn/data/list3/city" + code + ".xml";
  135. } else {
  136. address = "http://www.weather.com.cn/data/list3/city.xml";
  137. }
  138. showProgressDialog();
  139. HttpUtil.sendHttpRequest(address, new HttpCallbackListener() {
  140. @Override
  141. public void onFinish(String response) {
  142. boolean result = false;
  143. if ("province".equals(type)) {
  144. result = Utility.handleProvincesResponse(coolWeatherDB, response);
  145. } else if ("city".equals(type)) {
  146. result = Utility.handleCitiesResponse(coolWeatherDB, response, selectedProvince.getId());
  147. } else if ("county".equals(type)) {
  148. result = Utility.handleCountiesResponse(coolWeatherDB, response,selectedCity.getId());
  149. }
  150. if (result) {
  151. runOnUiThread(new Runnable() {
  152. @Override
  153. public void run() {
  154. closeProgressDialog();
  155. if ("province".equals(type)) {
  156. queryProvinces();
  157. } else if ("city".equals(type)) {
  158. queryCities();
  159. } else if ("county".equals(type)) {
  160. queryCounties();
  161. }
  162. }
  163. });
  164. }
  165. }
  166. @Override
  167. public void onError(Exception e) {
  168. runOnUiThread(new Runnable() {
  169. @Override
  170. public void run() {
  171. closeProgressDialog();
  172. Toast.makeText(ChooseAreaActivity.this, "加载失败",Toast.LENGTH_SHORT).show();
  173. }
  174. });
  175. }
  176. });
  177. }
  178. /*
  179. * 显示进度对话框
  180. * */
  181. private void closeProgressDialog() {
  182. if (progressDialog == null) {
  183. progressDialog = new ProgressDialog(this);
  184. progressDialog.setMessage("正在加载...");
  185. progressDialog.setCanceledOnTouchOutside(false);
  186. }
  187. progressDialog.show();
  188. }
  189. /*
  190. * 关闭进度对话框
  191. * */
  192. private void closeProgressDialog() {
  193. if (progressDialog != null) {
  194. progressDialog.dismiss();
  195. }
  196. }
  197. /*
  198. * 捕获Back按键,根据当前的级别来判断,此时应返回市列表、省列表、还是直接退出
  199. * */
  200. @Override
  201. public void onBackPressed() {
  202. if (currentLevel == LEVEL_COUNTY) {
  203. queryCities();
  204. } else if (currentLevel == LEVEL_CITY) {
  205. queryProvinces();
  206. } else {
  207. if (isFromWeatherActivity) {
  208. Intent intent = new Intent(this, WeatherActivity.class);
  209. startActivity(intent);
  210. }
  211. finish();
  212. }
  213. }

}

展开全部

  • 写回答

1条回答 默认 最新

  • danielinbiti 2016-03-22 01:39
    关注
    1. 代码中没有showProgressDialog方法定义
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
  • ¥15 fluent设置了自动保存后,会有几个时间点不保存
  • ¥20 激光照射到四象线探测器,通过液晶屏显示X、Y值
  • ¥15 这怎么做,怎么在我的思路下改下我这写的不对
  • ¥50 数据库开发问题求解答
  • ¥15 安装anaconda时报错
  • ¥15 小程序有个导出到插件方式,我是在分包下引入的插件,这个export的路径对吗,我看官方文档上写的是相对路径
  • ¥20 希望有人能帮我完成这个设计( *ˊᵕˋ)
  • ¥100 将Intptr传入SetHdevmode()将Intptr传入后转换为DEVMODE的值与外部代码不一致
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部