在主要活動試試這個代碼,您的微調
spin_category.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
category_id=arg2;
int my_id=db.getID(category_id);
}
public void onNothingSelected(AdapterView<?> arg0)
{
}
});
在你的數據庫類寫這個功能
public int getID(int id)
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[] { KEY_ID, KEY_NAME}, KEY_ID+"=?",
new String[] { String.valueOf(id) }, null);
if(cursor!=null)
if (cursor.getCount() > 0)
{
cursor.moveToFirst();
}
int s = cursor.getInt(cursor.getColumnIndex(KEY_ID));
cursor.close();
db.close();
return s;
}
的第一個函數將獲得所選項目的ID在微調,將它傳遞給數據庫的方法和二級功能將搜索ID,並返回該id ID。因爲我對你的要求不是很清楚。請評論,如果你想以不同的方式。