android开发中,利用 Spinner 从数据库中读取数据并实现2级互动时,在 Map<String,Integer> data = (Map)shopData.get(position);
出现 shopData cannot be resolved。
我的程序代码为
public class BeginActivity extends ListActivity{
private SQLiteDatabase database;
Spinner spinnershop,spinnershelf;
Button begin_scan;
TextView selectshop,selectshelf;
private Integer shopId, shelfId;
private ArrayAdapter<CharSequence> shop_adapter;
private ArrayAdapter<CharSequence> shelf_adapter;
private String strshop, stshelf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_scan);
spinnershop=(Spinner)findViewById(R.id.spinnershop);
spinnershelf=(Spinner)findViewById(R.id.spinnershelf);
begin_scan=(Button)findViewById(R.id.begin_scan);
selectshop=(TextView)findViewById(R.id.TextView03);
selectshelf=(TextView)findViewById(R.id.TextView04);
this.setTitle("盘点主界面");
Map<Integer,List> data = ShopDB.getShop();//得到数据库数据
//从门店货架号表中查找对应门店下的货架号
List shopList = data.get(1);
List shopData = data.get(0);
ArrayAdapter shop_adapter = new ArrayAdapter(BeginActivity.this,android.R.layout.simple_spinner_item,shopList);
shop_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 样式
spinnershop.setAdapter(shop_adapter);
spinnershop.setOnItemSelectedListener(itemSelectedListener);
}
// 选择门店联动 对应货架号
private OnItemSelectedListener itemSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Spinner spShop = (Spinner) parent;
String selShop = (String) spShop.getItemAtPosition(position);
Map<String,Integer> data = (Map)shopData.get(position);//根据所选择的门店得到对应的id 然后得到货架号
int pid = data.get(selShop);//得到门店的id
List shelfList = ShopDB.getCityByPid(pid);
shelf_adapter = new ArrayAdapter(BeginActivity.this,android.R.layout.simple_spinner_item,shelfList);
shelf_adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnershelf.setAdapter(shelf_adapter);
spinnershelf.setOnItemSelectedListener(citySelectedListener);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
};
String selectedShop = null;
private OnItemSelectedListener citySelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Spinner spShelf = (Spinner) parent;