上传者: aikjhhjkhg
|
上传时间: 2019-12-21 19:23:32
|
文件大小: 1.64MB
|
文件类型: doc
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 = cityMa