从数据库读取数据放入Spinner

来源:互联网 发布:js给table的td赋值 编辑:程序博客网 时间:2024/06/09 15:10

private void find_and_modify_view() {
  Cursor cursorSpn;   
  cursorSpn=cwjzDbAdapter.getCategory(); // getCategory(); 读取字段
  Spinner spn_categoryExist = (Spinner)findViewById(R.id.xml_spn_categoryExist);
  allcountries = new ArrayList<String>();
  for(cursorSpn.moveToFirst();!cursorSpn.isAfterLast();cursorSpn.moveToNext())
   {    

//移动cursor 将得到的数据放到ArrayList<String>();中
   allcountries.add(cursorSpn.getString(0));    
   }
  aspnCountries = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, allcountries);
  aspnCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spn_categoryExist.setAdapter(aspnCountries);

 }

原创粉丝点击