老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)

如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)

這篇文章將為大家詳細(xì)講解有關(guān)如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

10年積累的做網(wǎng)站、成都網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有費(fèi)縣免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

popupwindow中是三個(gè)wheelview,

<?xml version="1.0" encoding="utf-8"?>


 


 

 

 


 

 

 

 

 


 
 
 

 

b. 因?yàn)樯厦嬲f了,需要將文件copy到app目錄下,所以直接最好這代碼在application中寫,

package guozhaohui.com.wlylocationchoose;

import android.app.Application;

import java.io.InputStream;

import guozhaohui.com.wlylocationchoose.locationchoose.CityDataHelper;

/**
 * Created by ${GuoZhaoHui} on 2017/2/13.
 * Abstract:
 */

public class MyApplication extends Application {

 private CityDataHelper dataHelper;

 @Override
 public void onCreate() {
 super.onCreate();

 /**
 * 放在application中,讓app一啟動(dòng)就把raw中文件copy到 "/data/data/"+context.getPackageName()+"/databases/"
 * 這是app讀取數(shù)據(jù)的方法,不管是將數(shù)據(jù)庫文件放在raw或者assets中都是一樣
 */
 dataHelper=CityDataHelper.getInstance(this);
 InputStream in = this.getResources().openRawResource(R.raw.city);
 dataHelper.copyFile(in,CityDataHelper.DATABASE_NAME,CityDataHelper.DATABASES_DIR);

 }
}

c. popupwindow不是本次的重點(diǎn)也直接貼代碼。

 View popupView = LayoutInflater.from(this).inflate(R.layout.popup_locationchoose, null);
 mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
 mPopupWindow.setTouchable(true);
 mPopupWindow.setFocusable(true);
 mPopupWindow.setOutsideTouchable(true);
 mPopupWindow.setAnimationStyle(R.style.popup_locationchoose_bottom);

 // pickText = (TextView)popupView.findViewById(R.id.tv_pickText);
 provinceView = (WheelView)popupView.findViewById(R.id.provinceView);
 cityView = (WheelView)popupView.findViewById(R.id.cityView);
 districtView = (WheelView)popupView.findViewById(R.id.districtView);

 //確定或者取消
 btn_myinfo_sure = (TextView)popupView.findViewById(R.id.btn_myinfo_sure);
 btn_myinfo_cancel = (TextView) popupView.findViewById(R.id.btn_myinfo_cancel);
 btn_myinfo_cancel.setOnClickListener(this);
 btn_myinfo_sure.setOnClickListener(this);

設(shè)置三個(gè)wheelview的可見條目數(shù)

provinceView.setVisibleItems(7);
cityView.setVisibleItems(7);
districtView.setVisibleItems(7);

為三個(gè) wheelview添加滑動(dòng)事件

 // 添加change事件
 provinceView.addChangingListener(this);
 // 添加change事件
 cityView.addChangingListener(this);
 // 添加change事件
 districtView.addChangingListener(this);

c. 拿到操作數(shù)據(jù)的對(duì)象SQLiteDatabase

 db = dataHelper.openDataBase();

觀察數(shù)據(jù)庫文件可知這表中是根據(jù)字段level來判斷省市區(qū)的,如圖

如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)

同時(shí)我們也可知這省市區(qū)三個(gè)模型中的字段都是一樣的,都是

 private int cityID;
 private int parentId;
 private int level;
 private String name;
 private String pinyin;

不清楚的可以自己查下表,如圖,我查一個(gè)省

如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)

所以我們建立一樣的模型,雖然三個(gè)字段是一樣的,建一個(gè)就可以了,但是為了標(biāo)準(zhǔn)最好還是建三個(gè)。

package guozhaohui.com.wlylocationchoose.locationchoose.model;

public class ProvinceModel {

 private int cityID;
 private int parentId;
 private int level;
 private String name;
 private String pinyin;

 public int getCityID() {
 return cityID;
 }

 public void setCityID(int cityID) {
 this.cityID = cityID;
 }

 public int getParentId() {
 return parentId;
 }

 public void setParentId(int parentId) {
 this.parentId = parentId;
 }

 public int getLevel() {
 return level;
 }

 public void setLevel(int level) {
 this.level = level;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public String getPinyin() {
 return pinyin;
 }

 public void setPinyin(String pinyin) {
 this.pinyin = pinyin;
 }


}

進(jìn)行sql查詢,將查詢到的結(jié)果保存在cursor中,然后進(jìn)行一行行的循環(huán)遍歷,然后將遍歷一行的對(duì)象添加到這個(gè)對(duì)象的集合中。這里得到省的集合。

 public List getProvice(SQLiteDatabase db){
 String sql="SELECT * FROM ChooseCityModel where level = 1 ORDER BY cityID";
 Cursor cursor = db.rawQuery(sql,null);
 List list=new ArrayList();
 if (cursor!=null&&cursor.getCount() > 0) {
 while (cursor.moveToNext()){
 ProvinceModel provinceModel=new ProvinceModel();
 provinceModel.setCityID(cursor.getInt(cursor.getColumnIndex("cityID")));
 provinceModel.setParentId(cursor.getInt(cursor.getColumnIndex("parentId")));
 provinceModel.setLevel(cursor.getInt(cursor.getColumnIndex("level")));
 provinceModel.setName(cursor.getString(cursor.getColumnIndex("name")));
 provinceModel.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
 list.add(provinceModel);
 }
 }
 return list;
 }

根據(jù)表的結(jié)構(gòu),得到相應(yīng)的sql語句,希望根據(jù)上一級(jí)省的cityId得到下面的市,其實(shí)換句話說本級(jí)市的parentId就是上一級(jí)的cityid,不清楚的可以將sql語句查一遍,驗(yàn)證下對(duì)不對(duì),如圖

如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)

得到相應(yīng)省下面市的集合

 public List getCityByParentId(SQLiteDatabase db, String code){
 String sql="SELECT * FROM ChooseCityModel WHERE level = 2 and parentId = ? ORDER BY cityID";
 Cursor cursor = db.rawQuery(sql,new String[][code]);
 List list=new ArrayList();

 if (cursor!=null&&cursor.getCount() > 0) {

 while (cursor.moveToNext()){
 CityModel cityModel=new CityModel();
 cityModel.setCityID(cursor.getInt(cursor.getColumnIndex("cityID")));
 cityModel.setParentId(cursor.getInt(cursor.getColumnIndex("parentId")));
 cityModel.setLevel(cursor.getInt(cursor.getColumnIndex("level")));
 cityModel.setName(cursor.getString(cursor.getColumnIndex("name")));
 cityModel.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
 list.add(cityModel);
 }
 }
 return list;
 }

區(qū)也是一樣的,直接貼代碼了

 public List getDistrictById(SQLiteDatabase db, String code){
 //注意這里的parentId其實(shí)就是上一級(jí)的cityID
 String sql="SELECT * FROM ChooseCityModel WHERE level = 3 and parentId = ? ORDER BY cityID";
 Cursor cursor = db.rawQuery(sql,new String[][code]);
 List list=new ArrayList();
 if (cursor!=null&&cursor.getCount() > 0) {
 while (cursor.moveToNext()){
 DistrictModel districtModel=new DistrictModel();
 districtModel.setCityID(cursor.getInt(cursor.getColumnIndex("cityID")));
 districtModel.setParentId(cursor.getInt(cursor.getColumnIndex("parentId")));
 districtModel.setLevel(cursor.getInt(cursor.getColumnIndex("level")));
 districtModel.setName(cursor.getString(cursor.getColumnIndex("name")));
 districtModel.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
 list.add(districtModel);
 }
 }
 return list;
 }

d. 對(duì)彈出popuwindow顯示的wheelview進(jìn)行初始化,注釋都寫在代碼里,

 private void initpopData() {
 //初始化數(shù)據(jù)
 dataHelper = CityDataHelper.getInstance(this);
 db = dataHelper.openDataBase();
 provinceDatas = dataHelper.getProvice(db);
 if (provinceDatas.size() > 0) {

 //彈出popup時(shí),省wheelview中當(dāng)前的省其實(shí)就是省集合的第一個(gè)
 mCurrentProvince = provinceDatas.get(0).getName();

 //根據(jù)省cityid查詢到第一個(gè)省下面市的集合
 cityDatas = dataHelper.getCityByParentId(db, provinceDatas.get(0).getCityID()+"");
 }
 if (cityDatas.size() > 0) {
 //根據(jù)市cityid查詢到第一個(gè)市集合下面區(qū)的集合
 districtDatas = dataHelper.getDistrictById(db, cityDatas.get(0).getCityID()+"");

 }
 //wheelview的適配器代碼
 provinceAdapter = new ProvinceAdapter(this, provinceDatas);
 provinceAdapter.setTextSize(TEXTSIZE);//設(shè)置字體大小
 provinceView.setViewAdapter(provinceAdapter);

 updateCitys();
 updateAreas();
 }

更新省下面市的wheelview內(nèi)容,注釋很清楚,直接上代碼

 private void updateCitys() {
 int pCurrent = provinceView.getCurrentItem();
 if (provinceDatas.size() > 0) {
 //這里是必須的的,上面得到的集合只是第一個(gè)省下面所有市的集合及第一個(gè)市下面所有區(qū)的集合
 //這里得到的是相應(yīng)省下面對(duì)應(yīng)市的集合
 cityDatas = dataHelper.getCityByParentId(db, provinceDatas.get(pCurrent).getCityID()+"");
 } else {
 cityDatas.clear();
 }
 citysAdapter = new CitysAdapter(this, cityDatas);
 citysAdapter.setTextSize(TEXTSIZE);
 cityView.setViewAdapter(citysAdapter);
 if (cityDatas.size() > 0) {
 //默認(rèn)省下面 市wheelview滑動(dòng)第一個(gè),顯示第一個(gè)市
 cityView.setCurrentItem(0);
 mCurrentCity = cityDatas.get(0).getName();
 } else {
 mCurrentCity = "";
 }
 updateAreas();
 }

第三個(gè)wheelview和第二個(gè)一樣的,代碼直接上

 private void updateAreas() {
 int cCurrent = cityView.getCurrentItem();
 if (cityDatas.size() > 0) {
 districtDatas = dataHelper.getDistrictById(db, cityDatas.get(cCurrent).getCityID()+"");
 } else {
 districtDatas.clear();
 }
 areaAdapter = new AreaAdapter(this, districtDatas);
 areaAdapter.setTextSize(TEXTSIZE);
 districtView.setViewAdapter(areaAdapter);
 if (districtDatas.size() > 0) {
 mCurrentDistrict = districtDatas.get(0).getName();
 districtView.setCurrentItem(0);
 } else {
 mCurrentDistrict = "";
 }
 }

關(guān)于如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。


標(biāo)題名稱:如何在Android中使用WheelView實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)
本文地址:http://www.xueling.net.cn/article/jghgdc.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 91在线精品视频 | 四虎影视永久免费观看 | 91九色夫妻 | 久久狠狠亚洲综合 | 亚洲午夜精品无码专区在线观看 | 18禁动漫美女禁处被爆桶出水 | 欧美精品1 | 4438全国成人免费 | 远方的山楂树免费观看视频48集 | 九月婷婷人人澡人人添人人爽 | 女友的滋味在线观看 | 91成人免费在线观看 | 亚洲av乱码一区二区三区 | 久久久久亚洲AV成人网址 | 一级毛片在线视频免费观看 | 91免费在线视频 | 精品免费国产一区二区三区四区介绍 | 性色AV极品无码专区亚洲 | 欧美视频在线观看免费观 | 精品一区在线视频 | www日本黄色 | 超碰高清在线 | 亚洲男人第一天堂 | 精品久久久久久国产牛牛 | 澳门精品无码一区二区三区 | 亚洲精品日日夜夜 | 俺来俺也去www色在线观看 | 超碰91人人 | 老司机福利在线观看 | 麻豆视传媒短视频免费官网 | 亚洲cb精品一区二区三区 | 99久久一区二区 | 国产免费av片在线观看麻豆 | 一二三四中文在线 | 91麻豆精品国产综合久久久久久 | 亚洲九色 | 99久久久久成人国产免费 | 夜夜cao | 高清视频在线观看免费 | 国产高清在线a视频大全 | 欧美一区二区在线视频 |