我能够根据第一个微调器的选择来更改第二个和第三个微调器。
问题是第二个微调器,未根据需要显示。
示例:表名称为“ TABLE_LABELS”,而列(KEY_99 + ROUTE,KEY_ID,KEY_NAME)和数据为((“ 1”,“ 9001234”,“ 1超市”,“ N1”);(“ 2”,“ 9004567“,2 Supermarket”,“ N1”);(“ 3”,“ 9003562”,“ 2 Hypermarket”,“ N2”);(“ 4”,“ 9003561”,“ 4 oria”,“ N2”); (“ 5”,“ 9003565”,“ 3V Hypermarket1”,“ N2”);(“ 6”,“ 9003563”,“ dfictoeiea1”,“ N2”);(“ 7”,“ 9003564”,“ ermarket2”, “ N2”); (“ 8”,“ 9003569”,“ Lorcd2”,“ N2”);)
如果我在微调器1中选择了路线N2,则第二个微调器应显示与“ N2”匹配的所有路线,结果应为9003562,9003561,9003565,9003563,9003564,9003569。
目前,它仅基于“路线选择”显示一个。
数据库微调器信息:
public Cursor getAllLabelsForSpinner1AsCursor() {
String[] columns = new String[] {
"rowid AS _id, *"
}; // Need _id column for SimpleCursorAdapter
return this.getWritableDatabase().query(TABLE_LABELS, columns, null, null, null, null, null);
}
public Cursor getAllLabelsForSpinner2AsCursor(String keyFromSinner1) {
String[] columns = new String[] {
"rowid AS _id, *"
}; // Need _id column for SimpleCursorAdapter
return this.getWritableDatabase().query(TABLE_LABELS, columns, DatabaseHandler.ROUTE + " LIKE ?", new String[] {
keyFromSinner1 + "%"
},
null, null, null
);
}
public Cursor getAllLabelsForSpinner3AsCursor(String keyFromSpinner2) {
String[] columns = new String[] {
"rowid AS _id, *"
}; // Need _id column for SimpleCursorAdapter
return this.getWritableDatabase().query(
TABLE_LABELS, columns,
DatabaseHandler.ROUTE + " LIKE ?",
new String[] {
keyFromSpinner2 + "%"
},
null, null, null);
}
enter code here
主要活动:
private void manageSpinner1() {
spinner5csr = dbhndlr.getAllLabelsForSpinner1AsCursor();
if (sca5 == null) {
sca5 = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1,
spinner5csr,
new String[] {
DatabaseHandler.KEY_NAME
},
new int[] {
android.R.id.text1
},
0
);
s5.setAdapter(sca5);
s5.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView << ? > parent, View view, int position, long id) {
manageSpinner2(spinner5csr.getString(spinner5csr.getColumnIndex(DatabaseHandler.ROUTE)));
}
@Override
public void onNothingSelected(AdapterView << ? > parent) {}
});
} else {
sca5.swapCursor(spinner5csr);
}
}
private void manageSpinner2(String keyFromSpinner1) {
spinner2csr = dbhndlr.getAllLabelsForSpinner2AsCursor(keyFromSpinner1);
if (sca2 == null) {
sca2 = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
spinner2csr,
new String[] {
DatabaseHandler.ROUTE
},
new int[] {
android.R.id.text1
},
0
);
s1.setAdapter(sca2);
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView << ? > parent, View view, int position, long id) {
manageSpinner3(spinner2csr.getString(spinner2csr.getColumnIndex(DatabaseHandler.ROUTE)));
}
@Override
public void onNothingSelected(AdapterView << ? > parent) {
}
});
} else {
sca2.swapCursor(spinner2csr);
}
}
private void manageSpinner3(String keyForSpinner3) {
spinner3csr = dbhndlr.getAllLabelsForSpinner3AsCursor(keyForSpinner3);
if (sca3 == null) {
sca3 = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
spinner3csr,
new String[] {
DatabaseHandler.KEY_ID
},
new int[] {
android.R.id.text1
},
0
);
s2.setAdapter(sca3);
} else {
sca3.swapCursor(spinner3csr);
}
}