1

I'm trying to update listview when an item in spinner is selected,but it's not working fine.

这是我的微调器:

Spinner spnTypeSchool = (Spinner)findViewById(R.id.spnType);
spnTypeSchool.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,strarray));
spnTypeSchool.setOnItemSelectedListener(new OnItemSelectedListener() 
    {
     public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
     {
          spnItemClick = arg0.getItemIdAtPosition(arg2)+1;
          myDbHelper.open(); // my databaseHelper
         Cursor spnSelectSchoolType = myDbHelper.getSchoolTypeList(spnItemClick);
        if(spnSelectSchoolType != null && spnSelectSchoolType.moveToFirst())
        {
          do
          {        
              schoolTypeSelectedForSpinner.add(spnSelectSchoolType.getString(0).toString());
          }
          while(spnSelectSchoolType.moveToNext());
        }
        String[] strSchoolByTypeSelected = new String[schoolTypeSelectedForSpinner.size()];
        schoolTypeSelectedForSpinner.toArray(strSchoolByTypeSelected);
        myDbHelper.close();
    }
                        public void onNothingSelected(AdapterView<?> arg0) {/* TODO Auto-generated method stub*/}
   });

这是我的 ListView :

final ListView result = (ListView)findViewById(R.id.resultListView);
result.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,schoolTypeSelectedForSpinner));

这是我的数据库查询

public Cursor getSchoolTypeList(long sType)
    {
       return db.rawQuery("select school_name from tbl_school where s_type =\""+sType+"\"", null);
    }

我面临的问题是,当我选择项目时,列表视图没有正确更新。微调器上的第一个选择和第二个选择组合并返回不正确的值。

在此先感谢您的帮助....

4

0 回答 0