我知道這是不正確的,因爲它不起作用,但我不知道爲什麼這不起作用。有多個字符串的方法
我有多個spinners通過查詢從數據庫中填充。
vTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int
pos, long id) {
if(pos!=0){
Cursor vTypeChose = (Cursor)(vTypeSpinner.getSelectedItem());
if (vTypeChose != null) {
String typePicked = vTypeChose.getString(
vTypeChose.getColumnIndex(DataBaseHelper.POWERSPORTS_TYPE));
vMake = (Cursor) DataBaseHelper.getPowersportsMake(typePicked);
scaMake.changeCursor(vMake);
Log.e("SpinnerTest", "Type Selected: " + vType.getString(vType.getColumnIndex(DataBaseHelper.POWERSPORTS_TYPE)));
}
}
}
vMakeSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int
pos, long id) {
if(pos!=0){
Cursor vMakeChose = (Cursor)(vMakeSpinner.getSelectedItem());
if (vMakeChose != null) {
makePicked = vMakeChose.getString(
vMakeChose.getColumnIndex(DataBaseHelper.POWERSPORTS_MAKE));
vYear = (Cursor) DataBaseHelper.getPowersportsYear(typePicked, makePicked);
scaYear.changeCursor(vYear);
Log.e("SpinnerTest", "Make Selected: " + vMake.getString(vMake.getColumnIndex(DataBaseHelper.POWERSPORTS_MAKE)));
}
}
}
一旦vMakeSpinner項目被選中,它會啓動vYearSpinner代碼
這是我今年微調查詢
public static Cursor getPowersportsYear(String typePicked, String makePicked){
return myDataBase.query(POWERSPORTS_TABLE,
new String [] {POWERSPORTS_ID, POWERSPORTS_YEARS},
POWERSPORTS_TYPE+"='"+typePicked+"'" +" AND " + POWERSPORTS_MAKE+"='"+makePicked+"'",
null,
POWERSPORTS_YEARS,
null,
null);
}
如果我只有DataBaseHelper方法中的一個字符串值,它工作正常,但只有在有爭論的地方。
更新了一些代碼:
public class PowersportsEquivalent extends Activity {
DataBaseHelper myDbHelper;
String typePicked;
String makePicked;
String yearPicked;
SimpleCursorAdapter scaMake;
SimpleCursorAdapter scaYear;
Cursor vMake;
Cursor vYear;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_powersports_equivalent);
嘗試使用'POWERSPORTS_TYPE +「=」+ typePicked +「AND」+ POWERSPORTS_MAKE +「=」+ makePicked' –
應用程序與提供的代碼崩潰。給出一個LogCat錯誤:'12-20 11:11:55.195:E/AndroidRuntime(3180):android.database.sqlite.SQLiteException:near「makeDemo2」:語法錯誤(代碼1):編譯時:SELECT _id,powersports_years FROM powersports_data WHERE powersports_type = null AND powersports_make = makeDemo2 GROUP BY powersports_years' – LukeG224
'powersports_type = null'告訴你你的'typePicked'爲null,請檢查或在其中輸入手動值。 –