Android spinner 二级联动
//获取数据
public void run() {
List<B_province> b_provinces = new B_provinceServiceImpl()
.getObjs("select b_provinceId,provinceName,frontCode from b_province ");
List<B_city>beeu_citys = new B_cityServiceImpl()
.getObjs("select b_cityId,b_provinceId,cityName,frontCode from b_city ");
Message msg = handler.obtainMessage();
Bundle bundle = new Bundle();
msg.what = 0x102;
BundleData bundleData = new BundleData();
bundleData.setList(beeu_provinces);
bundle.putSerializable("bundleData", bundleData);
BundleData bundleData2=new BundleData();
bundleData2.setList(beeu_citys);
bundle.putSerializable("bundleData2", bundleData2);
msg.setData(bundle);
handler.sendMessage(msg);
}
// 数据
data_list_province = new ArrayList<String>();
data_list_city = new ArrayList<String>();
Thread thread = new Thread(this);
thread.start();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0x102) {
//省
List<B_province> b_provinces = (List<B_province>) ((BundleData) msg
.getData().getSerializable("bundleData")).getList();
Log.i(tag, "" + b_provinces.size());
for (B_province beeu_province : b_provinces) {
data_list_province.add(b_province.getProvinceName());
}
arr_adapter = new ArrayAdapter<String>(
City_Spinner.this,
android.R.layout.simple_spinner_item, data_list_province);
// 设置样式
arr_adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 加载适配器
beeu_province.setAdapter(adapter);
}
}
};
现在写setOnItemSelectedListener事件,想根据province的id查询city表得到同id的城市这里不太会写。获取不到province的id,希望给点头绪