sir i have two spinner in a view and in spinner value comes from sqlite manager database save in assets folder ...sir actualy i want when city is selected from 1st spinner then according to city selected location display on second spinner ..as i selected "noida" then location belongs to noida populate on spinner2 i m sending code for ur convienience...look it throughly pls....... notepadv3.java is....
**spinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
ArrayAdapter adapter2 = new ArrayAdapter<String>(gqMain.this, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter2);
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
}**
setResult(RESULT_OK);
}
});
try{
**Cursor cur1 = mDbHelper.getloc(cabbookingapplication.Selection);
this.startManagingCursor(cur1);
int accountnameIndex = cur1.getColumnIndexOrThrow("locationName");
if(cur1.moveToFirst()){
do{
//adapterForSpinner.add(c.getString(firstnameColumnIndex) + "aged " + c.getShort(ageColumnIndex));
adapter2.add(cur1.getString(accountnameIndex));
} while(cur1.moveToNext());**
}
and in databasehelperclass my getloc() is....
**public Cursor getloc(String selection)
{
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
Cursor cur1;
// gqMain gq= new gqMain();
//String ssss =gq.s11;
// String saa = cabbookingapplication.Selection;
// String sql = " select CityType.rowid from CityType where CityType.cityName = "+saa;
String sql = "SELECT CityType.rowid, Location.locationName FROM Location, CityType " +
"WHERE Location.cityId = CityType.rowid " 开发者_Go百科+
"AND CityType.cityName ='"+selection+"'";
//cur1 = myDataBase.rawQuery(
// " SELECT locationName FROM Location WHERE cityId in (" +sql+ ")",null);
Log.i("saurabh trivedi",sql);
cur1 = myDataBase.rawQuery(
sql, null);
cur1.moveToFirst();
return cur1;**
}
精彩评论