博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三级联动
阅读量:5156 次
发布时间:2019-06-13

本文共 3455 字,大约阅读时间需要 11 分钟。

1.demo.xml布局

2.MainActivity.java文件
public class MainActivity extends AppCompatActivity {
Spinner s_sheng; ArrayAdapter
adapter_sheng; ArrayAdapter
adapter_shi; ArrayAdapter
adapter_xian; Spinner s_shi; Spinner s_xian; int sheng_postion; int shi_postion; String seletced_sheng; String seletced_shi; String seletced_xian; TextView t_v; String[] arr_sheng = { "A小区", "B小区", "C小区", "D小区", "E小区", "F小区", "G小区"}; String[][] arr_shi = new String[][]{ { "1号楼1单元", "1号楼2单元", "1号楼3单元"}, { "2号楼1单元", "2号楼2单元", "2号楼3单元"}, { "3号楼1单元", "3号楼2单元", "3号楼3单元"}, { "4号楼1单元", "4号楼2单元", "4号楼3单元"}, { "5号楼1单元", "5号楼2单元", "5号楼3单元"}, { "6号楼1单元", "6号楼2单元", "6号楼3单元"}, { "7号楼1单元", "7号楼2单元", "7号楼3单元"},       {"8号楼1单元", "8号楼2单元", "8号楼3单元"} }; String[][][] arr_xian = new String[][][]{ {// {"0101", "0102", "0103", "0104"} }, {// {"0201", "0202", "0203", "0204"} }, {// {"0301", "0302", "0303", "0304"} }, {// {"0401", "0402", "0403", "0404"} }, {// {"0501", "0502", "0503", "0504"} }, {// {"0601", "0602", "0603", "0604"} }, {// {"0701", "0702", "0703", "0704"} }, {// {"0801", "0802", "0803", "0804"} } }; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); View rootView = View.inflate(this, R.layout.demo, null); setContentView(rootView); t_v = (TextView) findViewById(R.id.t_v); s_sheng = (Spinner) findViewById(R.id.sheng); s_shi = (Spinner) findViewById(R.id.shi); s_xian = (Spinner) findViewById(R.id.xian); adapter_sheng = new ArrayAdapter
(this, android.R.layout.simple_spinner_dropdown_item, arr_sheng); adapter_shi = new ArrayAdapter
(this, android.R.layout.simple_spinner_dropdown_item, arr_shi[0]); adapter_xian = new ArrayAdapter
(this, android.R.layout.simple_spinner_dropdown_item, arr_xian[0][0]); s_sheng.setAdapter(adapter_sheng); s_sheng.setSelection(0); s_shi.setAdapter(adapter_shi); s_shi.setSelection(0); s_xian.setAdapter(adapter_xian); s_xian.setSelection(0); s_sheng.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView
adapterView, View view, int i, long l) { Log.e("AAAAAAAAAAAA ", sheng_postion + " " + i); sheng_postion = i; adapter_shi = new ArrayAdapter
(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, arr_shi[i]); s_shi.setAdapter(adapter_shi); seletced_sheng = arr_sheng[i]; } @Override public void onNothingSelected(AdapterView
parent) { } }); s_shi.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView
adapterView, View view, int i, long l) {// shi_postion = i; adapter_xian = new ArrayAdapter
(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, arr_xian[sheng_postion][shi_postion]); s_xian.setAdapter(adapter_xian); seletced_shi = arr_shi[sheng_postion][i]; } @Override public void onNothingSelected(AdapterView
parent) { } }); s_xian.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView
adapterView, View view, int i, long l) { seletced_xian = arr_xian[sheng_postion][shi_postion][i]; t_v.setText(seletced_sheng + "-" + seletced_shi + "-" + seletced_xian); } @Override public void onNothingSelected(AdapterView
parent) { } }); }}
 

 

转载于:https://www.cnblogs.com/xiaoshumiao/p/8986946.html

你可能感兴趣的文章
DIOCP 运作核心探密
查看>>
You are not late! You are not early!
查看>>
基于Flask框架的Python web程序的开发实战 <二> 项目组织结构
查看>>
Linux grep及正则表达式
查看>>
P2023 [AHOI2009]维护序列
查看>>
HDU2216:Game III(BFS)
查看>>
JQuery语法 JQuery对象与原生对象互转 文档就绪函数与window.onload的区别
查看>>
swift-01-利用元组判断字符串出现次数
查看>>
LOJ10155数字转换
查看>>
JQuery实现轮播图及其原理
查看>>
zoj 3540
查看>>
Leetcode475.Heaters供暖器
查看>>
霍夫变换(Hough Transform)
查看>>
tomcat 内存溢出问题
查看>>
C++ OI图论 学习笔记(初步完结)
查看>>
USACO Broken Necklace
查看>>
中小型网站生存之道
查看>>
如何获取repeater某行第一列的值
查看>>
结对编程之实战
查看>>
TTButton 的正确使用的方法
查看>>