android 酷欧天气完整项目

本文介绍了一个基于Android的酷欧天气完整项目,涉及到province、city、county三个数据表的设计,用于存储省市县的天气信息。项目实现包括Province.java、ChooseAreaFragment.java和WeatherActivity.java等关键组件,源代码可在GitHub上获取。
摘要由CSDN通过智能技术生成

  先要建议三张表:province、city、county,分别用于存放省市县的数据信息。

Province.java

package com.example.lenovo.coolweather.db;

import org.litepal.crud.DataSupport;

/**
 * 代表省的数据库表
 */

public class Province extends DataSupport {
    private int id;    //id号
    private String provinceName;  //省得名字
    private int provinceCode;    //省得代号

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public int getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(int provinceCode) {
        this.provinceCode = provinceCode;
    }
}
City.java
package com.example.lenovo.coolweather.db;

import org.litepal.crud.DataSupport;

/**
 * 代表市的数据库表
 */

public class City extends DataSupport {
    private int id;
    private String cityName;  //城市名字
    private int cityCode;   //城市代号
    private int provinceId;   //当前城市所属省得id

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public int getCityCode() {
        return cityCode;
    }

    public void setCityCode(int cityCode) {
        this.cityCode = cityCode;
    }

    public int getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(int provinceId) {
        this.provinceId = provinceId;
    }
}
County.java
package com.example.lenovo.coolweather.db;

import org.litepal.crud.DataSupport;

/**
 * 代表县的数据库表
 */

public class County extends DataSupport {
    private int id;
    private String countName;  //县的名字
    private String weatherId;   //天气id
    private int cityId;    //当前县所属城市的id

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCountName() {
        return countName;
    }

    public void setCountName(String countName) {
        this.countName = countName;
    }

    public String getWeatherId() {
        return weatherId;
    }

    public void setWeatherId(String weatherId) {
        this.weatherId = weatherId;
    }

    public int getCityId() {
        return cityId;
    }

    public void setCityId(int cityId) {
        this.cityId = cityId;
    }
}

遍历省市县数据的碎片

ChooseAreaFragment.java

package com.example.lenovo.coolweather;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.lenovo.coolweather.db.City;
import com.example.lenovo.coolweather.db.County;
import com.example.lenovo.coolweather.db.Province;
import com.example.lenovo.coolweather.util.HttpUtil;
import com.example.lenovo.coolweather.util.Utility;

import org.litepal.crud.DataSupport;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * 遍历省市县数据的碎片
 */

public class ChooseAreaFragment extends Fragment {
    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 Button backButton;       //返回按钮
    private ListView listView;
    private ArrayAdapter<String> adapter;
    private List<String> dataList = new ArrayList<>();

    private List<Province> provinceList;   //省列表
    private List<City> cityList;  //市列表
    private List<County> countyList;  //县列表

    private Province selectProvince;  //选中的省份
    private City selectCity;  //选中的城市
    private int currentLevel;  //当前选中的级别

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值