填充微调数据

时间:2012-06-07 00:03:01

标签: android database cursor spinner

我的微调器有问题吗?我的应用程序没有崩溃,但吐司DB无法打开出现。所以我的旋转器人口必定有问题..有人可以帮助发现错误吗?谢谢!

// Open the DB, query all subject codes and refresh the listview
// when app resumes
   @Override
   protected void onResume() {
    super.onResume();

   ArrayList<String> menu = new ArrayList<String>();
    Spinner SpinMenu = (Spinner)this.findViewById(R.id.spinner1);
    SpinMenu.setAdapter(new ArrayAdapter<String>(this, 
        android.R.layout.simple_spinner_dropdown_item , menu));

    // Open/create the DB
    try {
        dbopener.createDatabase(); // Create DB if necessary
      dbopener.openDatabase(); // Open the DB

      Cursor menus = dbopener.getFood();
      while (menus.moveToNext()) {
         menu.add(menus.getString(0)); // Get the current subj
                                                  // code, add to list
      }
      menus.close();

      // Update the listview
      ArrayAdapter<String> ad = 
            (ArrayAdapter<String>)SpinMenu.getAdapter();
      ad.notifyDataSetChanged();

     SpinMenu.setOnItemSelectedListener(this);
    } catch (Exception e) {
        Toast.makeText(this, "Could not open DB", 
            Toast.LENGTH_LONG).show();
    }
}

0 个答案:

没有答案