sqlite query not working android -
these methods of spinners
mspinnermodel.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { selectedmodel = parent.getitematposition(position).tostring(); toast.maketext(parent.getcontext(), "selected model: " + selectedmodel, toast.length_long).show(); string sp1 = string.valueof(mspinnermodel.getselecteditem()); if (sp1.contentequals("college1")) { list<string> list = new arraylist<string>(); list.add("maharani university "); //list.add("manipal "); // list.add("itm university "); // list.add("university1"); // list.add("maharani universty"); arrayadapter<string> dataadapter = new arrayadapter<string>(mainactivity.this, android.r.layout.simple_spinner_item, list); dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter.notifydatasetchanged(); // selectedmake = parent.getitematposition(position).tostring(); mspinnermake.setadapter(dataadapter); } if (sp1.contentequals("college2")) { list<string> list1 = new arraylist<string>(); list1.add("itm university"); //list1.add("university2"); // list1.add("university3"); // selectedmake = parent.getitematposition(position).tostring(); arrayadapter<string> dataadapter2 = new arrayadapter<string>(mainactivity.this, android.r.layout.simple_spinner_dropdown_item, list1); dataadapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter2.notifydatasetchanged(); mspinnermake.setadapter(dataadapter2); } if (sp1.contentequals("college3")) { list<string> list = new arraylist<string>(); list.add("manipal "); //list.add("university4"); //list.add("university5"); arrayadapter<string> dataadapter3 = new arrayadapter<string>(mainactivity.this, android.r.layout.simple_spinner_dropdown_item, list); dataadapter3.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); dataadapter3.notifydatasetchanged(); mspinnermake.setadapter(dataadapter3); // selectedmake = parent.getitematposition(position).tostring(); } } @override public void onnothingselected(adapterview<?> parent) { } }); mspinnermake.setonitemselectedlistener(new adapterview.onitemselectedlistener(){ @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { selectedmake = parent.getitematposition(position).tostring(); } @override public void onnothingselected(adapterview<?> adapterview) { } }); mspinneryear.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { selectedyear = parent.getitematposition(position).tostring(); // showing selected spinner item toast.maketext(parent.getcontext(), "selected year: " + selectedyear, toast.length_long).show(); } @override public void onnothingselected(adapterview<?> parent) { } }); mbuttonshow.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string eligiblebattery=fetcheligiblebattery(msqlitedatabase); mtextviewresult.settext(eligiblebattery); } }); }
and method data , query fetching data not working. when select data in spinners shows in logcat not fetching data query right below not working please help.
private string fetcheligiblebattery(sqlitedatabase db) { string battery=""; string select_battery_query = "select "+ databaseconstants.key_battery+" " + databaseconstants.table_car_details + " " + databaseconstants.key_car_make + " ='" +selectedmake + "' , "+ databaseconstants.key_car_model +" = '"+ selectedmodel+ "' , "+ databaseconstants.key_car_year+"= '"+selectedyear +"' ;"; log.d("database", "battery select query : " + select_battery_query); cursor cursor = db.rawquery(select_battery_query, null); try { if (cursor.movetofirst()) { battery=cursor.getstring(cursor.getcolumnindex(databaseconstants.key_battery)); } } catch (exception e) { log.d("database", "error while trying icons database"); } { if (cursor != null && !cursor.isclosed()) { cursor.close(); } } return battery; } public void fetchdatafromdbforspinners(sqlitedatabase db) { string select_models_query = "select * " + databaseconstants.table_car_details + ";"; string model, make, year; cursor cursor = db.rawquery(select_models_query, null); try { if (cursor.movetofirst()) { { model = cursor.getstring(cursor.getcolumnindex(databaseconstants.key_car_model)); make = cursor.getstring(cursor.getcolumnindex(databaseconstants.key_car_make)); year = cursor.getstring(cursor.getcolumnindex(databaseconstants.key_car_year)); models.add(model); makes.add(make); years.add(year); } while (cursor.movetonext()); } } catch (exception e) { log.d("database", "error while trying events database"); } { if (cursor != null && !cursor.isclosed()) { cursor.close(); } }
this query wrong please check fixed code
string select_battery_query = "select "+ databaseconstants.key_battery+" " + databaseconstants.table_car_details + " " + databaseconstants.key_car_make + " = " +selectedmake +" , "+ databaseconstants.key_car_model +" = "+ selectedmodel+ " , "+ databaseconstants.key_car_year+"= "+selectedyear ";
Comments
Post a Comment