@SuppressWarnings("deprecation") public Date convertToDate(String dateS, Date date) { if (date == null) date = new Date(2000, 01, 01); date.setYear(Integer.parseInt(dateS.split("-")[0]) - 1900); date.setMonth(Integer.parseInt(dateS.split("-")[1]) - 1); date.setDate(Integer.parseInt(dateS.split("-")[2])); return date; }
@SuppressWarnings("deprecation") public void showResult() { /* 展示未来五天的天气情况 */ SimpleDateFormat formatterDate = new SimpleDateFormat("EEEE", Locale.CHINA); Date curDate = new Date(System.currentTimeMillis()); for (int i = 0; i < dayCount; i++) { /* 把星期+1,为下一次循环做准备 */ curDate.setDate(curDate.getDate() + 1); /* * 设置星期 */ TextView week = new TextView(this); week.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); week.setGravity(Gravity.CENTER); // 文字居中 // weeks[i].setTextColor(getResources().getColor(R.color.black));// // 设置文字颜色 week.setPadding(0, 0, 0, 0); // 文字在上下左右的边距 week.setSingleLine(true); // 文字在一行显示 week.setText(formatterDate.format(curDate)); /* * 设置天气图标 */ ImageView img = new ImageView(this); img.setLayoutParams(new LinearLayout.LayoutParams(45, 45)); img.setBackgroundResource(getImageId("b1_" + map.get("img" + (i * 2 + 3)))); /* * 温度 */ TextView temp = new TextView(this); temp.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); temp.setGravity(Gravity.CENTER); // 文字居中 // weeks[i].setTextColor(getResources().getColor(R.color.black));// // 设置文字颜色 temp.setPadding(0, 0, 0, 0); // 文字在上下左右的边距 temp.setSingleLine(true); // 文字在一行显示 temp.setText(map.get("temp" + (i + 2))); /* * 天气描述 */ TextView weather = new TextView(this); weather.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); weather.setGravity(Gravity.CENTER); // 文字居中 // weeks[i].setTextColor(getResources().getColor(R.color.black));// // 设置文字颜色 weather.setPadding(0, 0, 0, 0); // 文字在上下左右的边距 weather.setSingleLine(true); // 文字在一行显示 weather.setText(map.get("weather" + (i + 2))); /* * 风向 */ TextView wind = new TextView(this); wind.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); wind.setGravity(Gravity.CENTER); // 文字居中 // weeks[i].setTextColor(getResources().getColor(R.color.black));// // 设置文字颜色 wind.setPadding(0, 0, 0, 0); // 文字在上下左右的边距 wind.setSingleLine(true); // 文字在一行显示 wind.setText(map.get("wind" + (i + 2))); /* * 每一天布局 */ LinearLayout linear = new LinearLayout(this); linear.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1.0f)); linear.setOrientation(LinearLayout.VERTICAL); linear.setGravity(Gravity.CENTER); linear.addView(week); linear.addView(img); linear.addView(temp); linear.addView(weather); linear.addView(wind); /* 添加到最终显示的布局上 */ linear_user_first_other.addView(linear); } Log.i(TAG, "==showResult()"); String s1 = map.get("img1"); Log.i(TAG, "s1==" + s1); Log.i(TAG, "imageView_user_imgOne==" + imageView_user_imgOne); Log.i(TAG, "getImageId(s1)==" + getImageId("b1_" + s1)); imageView_user_imgOne.setImageResource(getImageId("b1_" + s1)); // 假设现在是白天 // if ("99".equals(s2)) { // img2.setVisibility(View.GONE); // } else { // img2.setImageResource(getImageId(s2)); // } textView_user_city.setText(map.get("city")); textView_user_temp.setText(map.get("temp1") + ""); textView_user_weather.setText(map.get("weather1") + "," + map.get("wind1")); textView_user_date.setText(map.get("date_y") + map.get("week")); // String str = "穿衣指数:" + map.get("index_d"); String str = "根据天气的状态,做出科学的护肤变化!皮肤敏感时!请慎重护肤补妆"; textView_user_index_d.setText(str); str = "紫外线:" + map.get("index_uv"); textView_user_index_uv.setText(str); str = "补妆:" + map.get("index_xc"); textView_user_index_xc.setText(str); str = "控油:" + map.get("index_tr"); textView_user_index_tr.setText(str); str = "舒适指数:" + map.get("index_co"); textView_user_index_co.setText(str); str = "卸妆:" + map.get("index_cl"); textView_user_index_cl.setText(str); str = "补水:" + map.get("index_ls"); textView_user_index_ls.setText(str); str = "过敏:" + map.get("index_ag"); textView_user_index_ag.setText(str); }