-
Android天气预报应用实验报告
资源介绍
Android天气预报实验报告模板
public class SetCityActivity extends Activity {
//定义的一个自动定位的列表
private ListView gpsView;
//定义的一个省份可伸缩性的列表
private ExpandableListView provinceList;
//定义的用于过滤的文本输入框
private TextView filterText;
//定义的一个记录城市码的SharedPreferences文件名
public static final String CITY_CODE_FILE="city_code";
//城市的编码
private String[][] cityCodes;
//省份
private String[] groups;
//对应的城市
private String[][] childs;
//自定义的伸缩列表适配器
private MyListAdapter adapter;
//记录应用程序widget的ID
private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_city);
gpsView = (ListView)findViewById(R.id.gps_view);
provinceList= (ExpandableListView)findViewById(R.id.provinceList);
//设置自动定位的适配器
gpsView.setAdapter(new GPSListAdapter(SetCityActivity.this));
//==============================GPS=================================
//当单击自动定位时
gpsView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
TextView localeCity = (TextView)view.findViewById(R.id.locateCityText);
localeCity.setText("正在定位...");
final LocateHandler handler = new LocateHandler(localeCity);
//添加一个线程来处理定位
new Thread(){
public void run() {
Map cityMap= getLocationCityInfo();
//记录匹配的城市的索引
int provinceIndex = -1;
int cityIndex = -1;
//传给处理类的数据封装对象
Bundle bundle = new Bundle();
if(cityMap!=null) {
//得到图家名
String country = cityMap.get(LocationXMLParser.COUNTRYNAME);
//只匹配中国地区的天气
if(country!=null&&country.equals("中国")){
//得到省
String province = cityMap.get(LocationXMLParser.ADMINISTRATIVEAREANAME);
//得到市
String city = cityMap.get(LocationXMLParser.LOCALITYNAME);
//得到区县
String towns = cityMap.get(LocationXMLParser.DEPENDENTLOCALITYNAME);
Log.i("GPS", "============"+province+"."+city+"."+towns+"==============");
//将GPS定位的城市与提供能查天气的城市进行匹配
StringBuilder matchCity = new StringBuilder(city);
matchCity.append(".");
matchCity.append(towns);
//找到省份
for(int i=0; i
- 上一篇: Android自定义控件---联系人列表A-Z排序
- 下一篇: Android 联系人列表