最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)城市選擇三級(jí)聯(lián)動(dòng)

 更新時(shí)間:2020年12月16日 11:40:02   作者:天才第一步_  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)城市選擇三級(jí)聯(lián)動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)城市選擇三級(jí)聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

效果圖,用于城市選擇三級(jí)聯(lián)動(dòng),帶ID返回

1. 添加依賴 

//三級(jí)聯(lián)動(dòng)
 implementation 'com.contrarywind:Android-PickerView:4.1.8'
 // gosn解析
 implementation 'com.google.code.gson:gson:2.8.5'

2.文件轉(zhuǎn)換成json串工具類

import android.content.Context;
import android.content.res.AssetManager;
 
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
 
/**
 * Created by dell on 2019/9/16.
 */
 
public class JsonFileReader {
 public static String getJson(Context context, String fileName) {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 try {
  AssetManager assetManager = context.getAssets();
  InputStream inputStream = assetManager.open(fileName);
  BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
  byte[] buffer = new byte[1024];
  int len;
  while ((len = bufferedInputStream.read(buffer)) != -1) {
  baos.write(buffer, 0, len);
  }
 } catch (IOException e) {
  e.printStackTrace();
 }
 return baos.toString();
 }
}

3.json轉(zhuǎn)換成集合工具類

import android.content.Context;
 
import com.google.gson.Gson;
 
import org.json.JSONArray;
 
import java.util.ArrayList;
 
/**
 * Created by dell on 2019/9/16.
 */
 
public class LevelsListDate {
 private ArrayList<JsonBean> options1Items = new ArrayList<>();
 private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
 private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();
 private Context context;
 
 public LevelsListDate(Context context) {
 this.context = context;
 }
 
 public ArrayList<JsonBean> initJsonData(String path) {
 String JsonData = JsonFileReader.getJson(context, path);
 options1Items.clear();
 options1Items = parseData(JsonData);//用Gson 轉(zhuǎn)成實(shí)體
 return options1Items;
 }
 
 public ArrayList<ArrayList<String>> initJsonData1(String path) {
 String JsonData = JsonFileReader.getJson(context, path);
 ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 轉(zhuǎn)成實(shí)體
 options2Items.clear();
 for (int i = 0; i < jsonBean.size(); i++) {//遍歷省份
  ArrayList<String> CityList = new ArrayList<>();//該省的城市列表(第二級(jí))
  ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//該省的所有地區(qū)列表(第三極)
  for (int c = 0; c < jsonBean.get(i).getCity().size(); c++) {//遍歷該省份的所有城市
  String CityName = jsonBean.get(i).getCity().get(c).getREGION_NAME();
  CityList.add(CityName);//添加城市
  ArrayList<String> City_AreaList = new ArrayList<>();//該城市的所有地區(qū)列表
  //如果無(wú)地區(qū)數(shù)據(jù),建議添加空字符串,防止數(shù)據(jù)為null 導(dǎo)致三個(gè)選項(xiàng)長(zhǎng)度不匹配造成崩潰
  if (jsonBean.get(i).getCity().get(c).getRes() == null
   || jsonBean.get(i).getCity().get(c).getRes().size() == 0) {
   City_AreaList.add("");
  } else {
   for (int d = 0; d < jsonBean.get(i).getCity().get(c).getRes().size(); d++) {//該城市對(duì)應(yīng)地區(qū)所有數(shù)據(jù)
   String AreaName = jsonBean.get(i).getCity().get(c).getRes().get(d).getREGION_NAME();
   City_AreaList.add(AreaName);//添加該城市所有地區(qū)數(shù)據(jù)
   }
  }
  Province_AreaList.add(City_AreaList);//添加該省所有地區(qū)數(shù)據(jù)
  }
  /**
  * 添加城市數(shù)據(jù)
  */
  options2Items.add(CityList);
 }
 return options2Items;
 }
 
 public ArrayList<ArrayList<ArrayList<String>>> initJsonData2(String path) {
 String JsonData = JsonFileReader.getJson(context, path);
 ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 轉(zhuǎn)成實(shí)體
 options3Items.clear();
 for (int i = 0; i < jsonBean.size(); i++) {//遍歷省份
  ArrayList<String> CityList = new ArrayList<>();//該省的城市列表(第二級(jí))
  ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//該省的所有地區(qū)列表(第三極)
  for (int c = 0; c < jsonBean.get(i).getCity().size(); c++) {//遍歷該省份的所有城市
  String CityName = jsonBean.get(i).getCity().get(c).getREGION_NAME();
  CityList.add(CityName);//添加城市
  ArrayList<String> City_AreaList = new ArrayList<>();//該城市的所有地區(qū)列表
  //如果無(wú)地區(qū)數(shù)據(jù),建議添加空字符串,防止數(shù)據(jù)為null 導(dǎo)致三個(gè)選項(xiàng)長(zhǎng)度不匹配造成崩潰
  if (jsonBean.get(i).getCity().get(c).getRes() == null
   || jsonBean.get(i).getCity().get(c).getRes().size() == 0) {
   City_AreaList.add("");
  } else {
   for (int d = 0; d < jsonBean.get(i).getCity().get(c).getRes().size(); d++) {//該城市對(duì)應(yīng)地區(qū)所有數(shù)據(jù)
   String AreaName = jsonBean.get(i).getCity().get(c).getRes().get(d).getREGION_NAME();
   City_AreaList.add(AreaName);//添加該城市所有地區(qū)數(shù)據(jù)
   }
  }
  Province_AreaList.add(City_AreaList);//添加該省所有地區(qū)數(shù)據(jù)
  }
  /**
  * 添加地區(qū)數(shù)據(jù)
  */
  options3Items.add(Province_AreaList);
 }
 return options3Items;
 }
 
 public ArrayList<JsonBean> parseData(String result) {//Gson 解析
 ArrayList<JsonBean> detail = new ArrayList<>();
 try {
  JSONArray data = new JSONArray(result);
  Gson gson = new Gson();
  for (int i = 0; i < data.length(); i++) {
  JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
  detail.add(entity);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }
 return detail;
 }
}

4.jsonBean類

import com.contrarywind.interfaces.IPickerViewData;
 
import java.util.List;
 
/**
 * Created by dell on 2019/9/16.
 */
 
public class JsonBean implements IPickerViewData {
 
 /**
 * ID : 7971
 * PARENT_ID : 7459
 * REGION_NAME : 遼寧省
 * city : [{"ID":7972,"PARENT_ID":7971,"REGION_NAME":"沈陽(yáng)市","res":[{"ID":7973,"PARENT_ID":7972,"REGION_NAME":"和平區(qū)"},{"ID":7974,"PARENT_ID":7972,"REGION_NAME":"沈河區(qū)"},{"ID":7975,"PARENT_ID":7972,"REGION_NAME":"大東區(qū)"},{"ID":7976,"PARENT_ID":7972,"REGION_NAME":"皇姑區(qū)"},{"ID":7977,"PARENT_ID":7972,"REGION_NAME":"鐵西區(qū)"},{"ID":7978,"PARENT_ID":7972,"REGION_NAME":"蘇家屯區(qū)"},{"ID":7979,"PARENT_ID":7972,"REGION_NAME":"東陵區(qū)"},{"ID":7980,"PARENT_ID":7972,"REGION_NAME":"新城子區(qū)"},{"ID":7981,"PARENT_ID":7972,"REGION_NAME":"于洪區(qū)"},{"ID":7982,"PARENT_ID":7972,"REGION_NAME":"遼中縣"},{"ID":7983,"PARENT_ID":7972,"REGION_NAME":"康平縣"},{"ID":7984,"PARENT_ID":7972,"REGION_NAME":"法庫(kù)縣"},{"ID":7985,"PARENT_ID":7972,"REGION_NAME":"新民市"},{"ID":7986,"PARENT_ID":7972,"REGION_NAME":"渾南新區(qū)"},{"ID":7987,"PARENT_ID":7972,"REGION_NAME":"張士開(kāi)發(fā)區(qū)"},{"ID":7988,"PARENT_ID":7972,"REGION_NAME":"沈北新區(qū)"},{"ID":7989,"PARENT_ID":7972,"REGION_NAME":"其它區(qū)"}]},{"ID":7990,"PARENT_ID":7971,"REGION_NAME":"大連市","res":[{"ID":7991,"PARENT_ID":7990,"REGION_NAME":"中山區(qū)"},{"ID":7992,"PARENT_ID":7990,"REGION_NAME":"西崗區(qū)"},{"ID":7993,"PARENT_ID":7990,"REGION_NAME":"沙河口區(qū)"},{"ID":7994,"PARENT_ID":7990,"REGION_NAME":"甘井子區(qū)"},{"ID":7995,"PARENT_ID":7990,"REGION_NAME":"旅順口區(qū)"},{"ID":7996,"PARENT_ID":7990,"REGION_NAME":"金州區(qū)"},{"ID":7997,"PARENT_ID":7990,"REGION_NAME":"長(zhǎng)海縣"},{"ID":7998,"PARENT_ID":7990,"REGION_NAME":"開(kāi)發(fā)區(qū)"},{"ID":7999,"PARENT_ID":7990,"REGION_NAME":"瓦房店市"},{"ID":8000,"PARENT_ID":7990,"REGION_NAME":"普蘭店市"},{"ID":8001,"PARENT_ID":7990,"REGION_NAME":"莊河市"},{"ID":8002,"PARENT_ID":7990,"REGION_NAME":"嶺前區(qū)"},{"ID":8003,"PARENT_ID":7990,"REGION_NAME":"其它區(qū)"}]},{"ID":8004,"PARENT_ID":7971,"REGION_NAME":"鞍山市","res":[{"ID":8005,"PARENT_ID":8004,"REGION_NAME":"鐵東區(qū)"},{"ID":8006,"PARENT_ID":8004,"REGION_NAME":"鐵西區(qū)"},{"ID":8007,"PARENT_ID":8004,"REGION_NAME":"立山區(qū)"},{"ID":8008,"PARENT_ID":8004,"REGION_NAME":"千山區(qū)"},{"ID":8009,"PARENT_ID":8004,"REGION_NAME":"臺(tái)安縣"},{"ID":8010,"PARENT_ID":8004,"REGION_NAME":"岫巖滿族自治縣"},{"ID":8011,"PARENT_ID":8004,"REGION_NAME":"高新區(qū)"},{"ID":8012,"PARENT_ID":8004,"REGION_NAME":"海城市"},{"ID":8013,"PARENT_ID":8004,"REGION_NAME":"其它區(qū)"}]},{"ID":8014,"PARENT_ID":7971,"REGION_NAME":"撫順市","res":[{"ID":8015,"PARENT_ID":8014,"REGION_NAME":"新?lián)釁^(qū)"},{"ID":8016,"PARENT_ID":8014,"REGION_NAME":"東洲區(qū)"},{"ID":8017,"PARENT_ID":8014,"REGION_NAME":"望花區(qū)"},{"ID":8018,"PARENT_ID":8014,"REGION_NAME":"順城區(qū)"},{"ID":8019,"PARENT_ID":8014,"REGION_NAME":"撫順縣"},{"ID":8020,"PARENT_ID":8014,"REGION_NAME":"新賓滿族自治縣"},{"ID":8021,"PARENT_ID":8014,"REGION_NAME":"清原滿族自治縣"},{"ID":8022,"PARENT_ID":8014,"REGION_NAME":"其它區(qū)"}]},{"ID":8023,"PARENT_ID":7971,"REGION_NAME":"本溪市","res":[{"ID":8024,"PARENT_ID":8023,"REGION_NAME":"平山區(qū)"},{"ID":8025,"PARENT_ID":8023,"REGION_NAME":"溪湖區(qū)"},{"ID":8026,"PARENT_ID":8023,"REGION_NAME":"明山區(qū)"},{"ID":8027,"PARENT_ID":8023,"REGION_NAME":"南芬區(qū)"},{"ID":8028,"PARENT_ID":8023,"REGION_NAME":"本溪滿族自治縣"},{"ID":8029,"PARENT_ID":8023,"REGION_NAME":"桓仁滿族自治縣"},{"ID":8030,"PARENT_ID":8023,"REGION_NAME":"其它區(qū)"}]},{"ID":8031,"PARENT_ID":7971,"REGION_NAME":"丹東市","res":[{"ID":8032,"PARENT_ID":8031,"REGION_NAME":"元寶區(qū)"},{"ID":8033,"PARENT_ID":8031,"REGION_NAME":"振興區(qū)"},{"ID":8034,"PARENT_ID":8031,"REGION_NAME":"振安區(qū)"},{"ID":8035,"PARENT_ID":8031,"REGION_NAME":"寬甸滿族自治縣"},{"ID":8036,"PARENT_ID":8031,"REGION_NAME":"東港市"},{"ID":8037,"PARENT_ID":8031,"REGION_NAME":"鳳城市"},{"ID":8038,"PARENT_ID":8031,"REGION_NAME":"其它區(qū)"}]},{"ID":8039,"PARENT_ID":7971,"REGION_NAME":"錦州市","res":[{"ID":8040,"PARENT_ID":8039,"REGION_NAME":"古塔區(qū)"},{"ID":8041,"PARENT_ID":8039,"REGION_NAME":"凌河區(qū)"},{"ID":8042,"PARENT_ID":8039,"REGION_NAME":"太和區(qū)"},{"ID":8043,"PARENT_ID":8039,"REGION_NAME":"黑山縣"},{"ID":8044,"PARENT_ID":8039,"REGION_NAME":"義縣"},{"ID":8045,"PARENT_ID":8039,"REGION_NAME":"凌海市"},{"ID":8046,"PARENT_ID":8039,"REGION_NAME":"北鎮(zhèn)市"},{"ID":8047,"PARENT_ID":8039,"REGION_NAME":"其它區(qū)"}]},{"ID":8048,"PARENT_ID":7971,"REGION_NAME":"營(yíng)口市","res":[{"ID":8049,"PARENT_ID":8048,"REGION_NAME":"站前區(qū)"},{"ID":8050,"PARENT_ID":8048,"REGION_NAME":"西市區(qū)"},{"ID":8051,"PARENT_ID":8048,"REGION_NAME":"鲅魚(yú)圈區(qū)"},{"ID":8052,"PARENT_ID":8048,"REGION_NAME":"老邊區(qū)"},{"ID":8053,"PARENT_ID":8048,"REGION_NAME":"蓋州市"},{"ID":8054,"PARENT_ID":8048,"REGION_NAME":"大石橋市"},{"ID":8055,"PARENT_ID":8048,"REGION_NAME":"其它區(qū)"}]},{"ID":8056,"PARENT_ID":7971,"REGION_NAME":"阜新市","res":[{"ID":8057,"PARENT_ID":8056,"REGION_NAME":"海州區(qū)"},{"ID":8058,"PARENT_ID":8056,"REGION_NAME":"新邱區(qū)"},{"ID":8059,"PARENT_ID":8056,"REGION_NAME":"太平區(qū)"},{"ID":8060,"PARENT_ID":8056,"REGION_NAME":"清河門區(qū)"},{"ID":8061,"PARENT_ID":8056,"REGION_NAME":"細(xì)河區(qū)"},{"ID":8062,"PARENT_ID":8056,"REGION_NAME":"阜新蒙古族自治縣"},{"ID":8063,"PARENT_ID":8056,"REGION_NAME":"彰武縣"},{"ID":8064,"PARENT_ID":8056,"REGION_NAME":"其它區(qū)"}]},{"ID":8065,"PARENT_ID":7971,"REGION_NAME":"遼陽(yáng)市","res":[{"ID":8066,"PARENT_ID":8065,"REGION_NAME":"白塔區(qū)"},{"ID":8067,"PARENT_ID":8065,"REGION_NAME":"文圣區(qū)"},{"ID":8068,"PARENT_ID":8065,"REGION_NAME":"宏偉區(qū)"},{"ID":8069,"PARENT_ID":8065,"REGION_NAME":"弓長(zhǎng)嶺區(qū)"},{"ID":8070,"PARENT_ID":8065,"REGION_NAME":"太子河區(qū)"},{"ID":8071,"PARENT_ID":8065,"REGION_NAME":"遼陽(yáng)縣"},{"ID":8072,"PARENT_ID":8065,"REGION_NAME":"燈塔市"},{"ID":8073,"PARENT_ID":8065,"REGION_NAME":"其它區(qū)"}]},{"ID":8074,"PARENT_ID":7971,"REGION_NAME":"盤錦市","res":[{"ID":8075,"PARENT_ID":8074,"REGION_NAME":"雙臺(tái)子區(qū)"},{"ID":8076,"PARENT_ID":8074,"REGION_NAME":"興隆臺(tái)區(qū)"},{"ID":8077,"PARENT_ID":8074,"REGION_NAME":"大洼縣"},{"ID":8078,"PARENT_ID":8074,"REGION_NAME":"盤山縣"},{"ID":8079,"PARENT_ID":8074,"REGION_NAME":"其它區(qū)"}]},{"ID":8080,"PARENT_ID":7971,"REGION_NAME":"鐵嶺市","res":[{"ID":8081,"PARENT_ID":8080,"REGION_NAME":"銀州區(qū)"},{"ID":8082,"PARENT_ID":8080,"REGION_NAME":"清河區(qū)"},{"ID":8083,"PARENT_ID":8080,"REGION_NAME":"鐵嶺縣"},{"ID":8084,"PARENT_ID":8080,"REGION_NAME":"西豐縣"},{"ID":8085,"PARENT_ID":8080,"REGION_NAME":"昌圖縣"},{"ID":8086,"PARENT_ID":8080,"REGION_NAME":"調(diào)兵山市"},{"ID":8087,"PARENT_ID":8080,"REGION_NAME":"開(kāi)原市"},{"ID":8088,"PARENT_ID":8080,"REGION_NAME":"其它區(qū)"}]},{"ID":8089,"PARENT_ID":7971,"REGION_NAME":"朝陽(yáng)市","res":[{"ID":8090,"PARENT_ID":8089,"REGION_NAME":"雙塔區(qū)"},{"ID":8091,"PARENT_ID":8089,"REGION_NAME":"龍城區(qū)"},{"ID":8092,"PARENT_ID":8089,"REGION_NAME":"朝陽(yáng)縣"},{"ID":8093,"PARENT_ID":8089,"REGION_NAME":"建平縣"},{"ID":8094,"PARENT_ID":8089,"REGION_NAME":"喀喇沁左翼蒙古族自治縣"},{"ID":8095,"PARENT_ID":8089,"REGION_NAME":"北票市"},{"ID":8096,"PARENT_ID":8089,"REGION_NAME":"凌源市"},{"ID":8097,"PARENT_ID":8089,"REGION_NAME":"其它區(qū)"}]},{"ID":8098,"PARENT_ID":7971,"REGION_NAME":"葫蘆島市","res":[{"ID":8099,"PARENT_ID":8098,"REGION_NAME":"連山區(qū)"},{"ID":8100,"PARENT_ID":8098,"REGION_NAME":"龍港區(qū)"},{"ID":8101,"PARENT_ID":8098,"REGION_NAME":"南票區(qū)"},{"ID":8102,"PARENT_ID":8098,"REGION_NAME":"綏中縣"},{"ID":8103,"PARENT_ID":8098,"REGION_NAME":"建昌縣"},{"ID":8104,"PARENT_ID":8098,"REGION_NAME":"興城市"},{"ID":8105,"PARENT_ID":8098,"REGION_NAME":"其它區(qū)"}]}]
 */
 
 private int ID;
 private int PARENT_ID;
 private String REGION_NAME;
 private List<CityBean> city;
 
 public int getID() {
 return ID;
 }
 
 public void setID(int ID) {
 this.ID = ID;
 }
 
 public int getPARENT_ID() {
 return PARENT_ID;
 }
 
 public void setPARENT_ID(int PARENT_ID) {
 this.PARENT_ID = PARENT_ID;
 }
 
 public String getREGION_NAME() {
 return REGION_NAME;
 }
 
 public void setREGION_NAME(String REGION_NAME) {
 this.REGION_NAME = REGION_NAME;
 }
 
 public List<CityBean> getCity() {
 return city;
 }
 
 public void setCity(List<CityBean> city) {
 this.city = city;
 }
 
 @Override
 public String getPickerViewText() {
 return this.REGION_NAME;
 }
 
 public static class CityBean {
 /**
  * ID : 7972
  * PARENT_ID : 7971
  * REGION_NAME : 沈陽(yáng)市
  * res : [{"ID":7973,"PARENT_ID":7972,"REGION_NAME":"和平區(qū)"},{"ID":7974,"PARENT_ID":7972,"REGION_NAME":"沈河區(qū)"},{"ID":7975,"PARENT_ID":7972,"REGION_NAME":"大東區(qū)"},{"ID":7976,"PARENT_ID":7972,"REGION_NAME":"皇姑區(qū)"},{"ID":7977,"PARENT_ID":7972,"REGION_NAME":"鐵西區(qū)"},{"ID":7978,"PARENT_ID":7972,"REGION_NAME":"蘇家屯區(qū)"},{"ID":7979,"PARENT_ID":7972,"REGION_NAME":"東陵區(qū)"},{"ID":7980,"PARENT_ID":7972,"REGION_NAME":"新城子區(qū)"},{"ID":7981,"PARENT_ID":7972,"REGION_NAME":"于洪區(qū)"},{"ID":7982,"PARENT_ID":7972,"REGION_NAME":"遼中縣"},{"ID":7983,"PARENT_ID":7972,"REGION_NAME":"康平縣"},{"ID":7984,"PARENT_ID":7972,"REGION_NAME":"法庫(kù)縣"},{"ID":7985,"PARENT_ID":7972,"REGION_NAME":"新民市"},{"ID":7986,"PARENT_ID":7972,"REGION_NAME":"渾南新區(qū)"},{"ID":7987,"PARENT_ID":7972,"REGION_NAME":"張士開(kāi)發(fā)區(qū)"},{"ID":7988,"PARENT_ID":7972,"REGION_NAME":"沈北新區(qū)"},{"ID":7989,"PARENT_ID":7972,"REGION_NAME":"其它區(qū)"}]
  */
 
 private int ID;
 private int PARENT_ID;
 private String REGION_NAME;
 private List<ResBean> res;
 
 public int getID() {
  return ID;
 }
 
 public void setID(int ID) {
  this.ID = ID;
 }
 
 public int getPARENT_ID() {
  return PARENT_ID;
 }
 
 public void setPARENT_ID(int PARENT_ID) {
  this.PARENT_ID = PARENT_ID;
 }
 
 public String getREGION_NAME() {
  return REGION_NAME;
 }
 
 public void setREGION_NAME(String REGION_NAME) {
  this.REGION_NAME = REGION_NAME;
 }
 
 public List<ResBean> getRes() {
  return res;
 }
 
 public void setRes(List<ResBean> res) {
  this.res = res;
 }
 
 public static class ResBean {
  /**
  * ID : 7973
  * PARENT_ID : 7972
  * REGION_NAME : 和平區(qū)
  */
 
  private int ID;
  private int PARENT_ID;
  private String REGION_NAME;
 
  public int getID() {
  return ID;
  }
 
  public void setID(int ID) {
  this.ID = ID;
  }
 
  public int getPARENT_ID() {
  return PARENT_ID;
  }
 
  public void setPARENT_ID(int PARENT_ID) {
  this.PARENT_ID = PARENT_ID;
  }
 
  public String getREGION_NAME() {
  return REGION_NAME;
  }
 
  public void setREGION_NAME(String REGION_NAME) {
  this.REGION_NAME = REGION_NAME;
  }
 }
 }
}

5.主頁(yè)調(diào)用,城市json數(shù)據(jù)很多解析耗時(shí),進(jìn)入頁(yè)面會(huì)非常的慢,所以在子線程調(diào)用。有的地址沒(méi)有第三級(jí)trycach,有就取沒(méi)有就去二級(jí)

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
 
import java.util.ArrayList;
 
 
public class MainActivity extends AppCompatActivity {
 private TextView tvAddress;
 private OptionsPickerView pvOptions;
 private LevelsListDate levelsListDate;
 private ArrayList<JsonBean> jsonBeans;
 private ArrayList<ArrayList<String>> arrayLists;
 private ArrayList<ArrayList<ArrayList<String>>> arrayLists1;
 private Handler handler1 = new Handler() {
 @Override
 public void handleMessage(Message msg) {
  super.handleMessage(msg);
  try {
  showHyPickerView();
  } catch (Exception e) {
  e.printStackTrace();
  }
 }
 };
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 tvAddress = findViewById(R.id.tvAddress);
 tvAddress.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  if (pvOptions != null) {
   pvOptions.show();
  }
  }
 });
 new Thread(new Runnable() {
  @Override
  public void run() {
  try {
   levelsListDate = new LevelsListDate(MainActivity.this);
   jsonBeans = levelsListDate.initJsonData("citys_data.json");
   arrayLists = levelsListDate.initJsonData1("citys_data.json");
   arrayLists1 = levelsListDate.initJsonData2("citys_data.json");
   handler1.sendEmptyMessage(1);
  } catch (Exception e) {
   e.printStackTrace();
  }
  }
 }).start();
 }
 
 /**
 * 初始化城市選擇器
 */
 private void showHyPickerView() {
 //條件選擇器
 pvOptions = new OptionsPickerBuilder(MainActivity.this, new com.bigkoo.pickerview.listener.OnOptionsSelectListener() {
  @Override
  public void onOptionsSelect(int options1, int options2, int options3, View v) {
  try {
   // cityId = jsonBeans.get(options1).getCity().get(options2).getRes().get(options3).getID() + "";
   tvAddress.setText(jsonBeans.get(options1).getCity().get(options2).getRes().get(options3).getREGION_NAME());
  } catch (Exception e) {
   // cityId = jsonBeans.get(options1).getCity().get(options2).getID() + "";
   tvAddress.setText(jsonBeans.get(options1).getCity().get(options2).getREGION_NAME());
  }
  }
 }).build();
 pvOptions.setPicker(jsonBeans, arrayLists, arrayLists1);
 }
}

github地址

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)帶進(jìn)度條的WebView

    Android實(shí)現(xiàn)帶進(jìn)度條的WebView

    這篇文章主要介紹了Android實(shí)現(xiàn)帶進(jìn)度條的WebView,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android 10 適配攻略小結(jié)

    Android 10 適配攻略小結(jié)

    這篇文章主要介紹了Android 10 適配攻略小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Android控件拖動(dòng)實(shí)例詳解

    Android控件拖動(dòng)實(shí)例詳解

    這篇文章主要介紹了 Android控件的拖動(dòng)實(shí)例詳解的相關(guān)資料,這里附有實(shí)例代碼,幫助大家學(xué)習(xí)理解,需要的朋友可以參考下
    2016-12-12
  • Android實(shí)現(xiàn)橫向二級(jí)菜單

    Android實(shí)現(xiàn)橫向二級(jí)菜單

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)橫向二級(jí)菜單的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Kotlin基礎(chǔ)學(xué)習(xí)之循環(huán)和異常

    Kotlin基礎(chǔ)學(xué)習(xí)之循環(huán)和異常

    最近在學(xué)習(xí)kotlin,Kotlin 是一個(gè)基于 JVM 的新的編程語(yǔ)言,下面這篇文章主要給大家介紹了關(guān)于Kotlin基礎(chǔ)學(xué)習(xí)之循環(huán)和異常的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-12-12
  • Android?Gradle同步優(yōu)化詳解

    Android?Gradle同步優(yōu)化詳解

    這篇文章主要為大家介紹了Android?Gradle同步優(yōu)化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • Android自定義日歷控件實(shí)例詳解

    Android自定義日歷控件實(shí)例詳解

    這篇文章主要為大家詳細(xì)介紹了Android自定義日歷控件的實(shí)現(xiàn)過(guò)程,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android6.0 屏幕固定功能詳解

    Android6.0 屏幕固定功能詳解

    android6.0在設(shè)置->安全->屏幕固定開(kāi)啟后,然后再長(zhǎng)按home鍵出現(xiàn)最近的幾個(gè)Activity可以選擇一個(gè)圖釘按鈕就開(kāi)啟了屏幕固定功能。這篇文章主要介紹了Android6.0 屏幕固定功能的相關(guān)資料,感興趣的朋友一起看看吧
    2016-09-09
  • Android 多個(gè)Activity之間的傳值

    Android 多個(gè)Activity之間的傳值

    本篇文章將用一個(gè)實(shí)例,詳細(xì)的為大家講解怎么注冊(cè)并激活一個(gè)新的Activity,以及多個(gè)Activity之間如何傳值
    2013-11-11
  • Android camera實(shí)時(shí)預(yù)覽 實(shí)時(shí)處理,人臉識(shí)別示例

    Android camera實(shí)時(shí)預(yù)覽 實(shí)時(shí)處理,人臉識(shí)別示例

    本篇文章主要介紹了Android camera實(shí)時(shí)預(yù)覽 實(shí)時(shí)處理,面部認(rèn)證示例,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01

最新評(píng)論

通化市| 探索| 防城港市| 江西省| 新晃| 凉山| 黔西| 贵州省| 兰考县| 临邑县| 汨罗市| 黔西县| 称多县| 三穗县| 郯城县| 桐庐县| 元江| 波密县| 盐边县| 荥阳市| 双城市| 大化| 布拖县| 石首市| 买车| 岳阳县| 迁安市| 桂阳县| 喀喇沁旗| 陕西省| 定远县| 出国| 项城市| 霸州市| 唐河县| 芷江| 新化县| 靖边县| 抚州市| 阿瓦提县| 铜陵市|