android - How to populate spinner data based on from and to dates from sqlite database? -
i have written program insert data includes column called date, when inserting date inserted @ same time.
insertion working perfectly, in different activity have 2 edittexts fromdate , todate when clicked separate datepicker open , selected date set on respective edittext, want when have finished selecting date , date, want spinner populated based on date have inserted data.
i have tried not working though.
this table have created
private static final string create_table_finaldata = "create table "+table_name_finaldata+" (" +uid +" integer primary key, "+reference_no+" varchar(200), "+account_name+" varchar(200), "+account_type+" varchar(100) ,"+vehicle_no+" varchar(100), "+driver_code+" varchar(50), "+driver_name+" varchar(200), "+diesel_type+" varchar(50), "+diesel_rate+" double, "+diesel_quantity+" double, "+amount +" double, "+effective_date+" varchar(255), "+no_of_copies +" varchar(10), "+time+" varchar(255), "+transaction_id+" varchar(500), "+remark+" varchar(500), "+sync+" varchar(20), "+client_code+" varchar(255))"; private static final string drop_table_finaldata = "drop table if exists "+table_name_finaldata;
this query getting values of accountname based on dates
public cursor getaccname(string fromdate, string todate) { sqlitedatabase db = helper.getwritabledatabase(); cursor cursor = db.rawquery("select "+dblisthelper.account_name+", "+dblisthelper.uid+ " " + dblisthelper.table_name_finaldata + " "+dblisthelper.effective_date+"between"+dblisthelper.effective_date + " = '" + fromdate + "' , " + dblisthelper.effective_date + " = '" + todate + "'", null); return cursor; }
this activity code
@override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.view_records); spinneraccountname = (spinner) findviewbyid(r.id.spinneraccountname); imgback = (imageview) findviewbyid(r.id.imgback); etfromdate = (autocompletetextview) findviewbyid(r.id.editfromdate); ettodate = (autocompletetextview) findviewbyid(r.id.edittodate); txttotalcount = (textview) findviewbyid(r.id.noofslips); txtdieselqty = (textview) findviewbyid(r.id.dieselquantity); txtdieselamnt = (textview) findviewbyid(r.id.amount); cal = calendar.getinstance(); day = cal.get(calendar.day_of_month); month = cal.get(calendar.month); year = cal.get(calendar.year); listhelper = new sqlitevehicledetails(getbasecontext()); listhelper.open(getbasecontext()); etfromdate.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { showdialog(date_picker_id); } }); ettodate.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { showdialog(date_picker_id_1); } }); etfromdate.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { if (cursor.movetofirst()) { string fromdate = cursor.getstring(cursor.getcolumnindex(dblisthelper.effective_date)); string todate = cursor.getstring(cursor.getcolumnindex(dblisthelper.effective_date)); cursor = listhelper.getaccname(fromdate, todate); int[] to5 = new int[]{android.r.id.text1}; string[] from5 = new string[]{dblisthelper.account_name}; final simplecursoradapter adapter5 = new simplecursoradapter( getbasecontext(), android.r.layout.simple_list_item_1, cursor, from5, to5 ); adapter5.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinneraccountname.setadapter(adapter5); } } }); ettodate.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void aftertextchanged(editable s) { cursor = listhelper.getfinaldata(); if (cursor.movetofirst()) { string fromdate = cursor.getstring(cursor.getcolumnindex(dblisthelper.effective_date)); string todate = cursor.getstring(cursor.getcolumnindex(dblisthelper.effective_date)); cursor = listhelper.getaccname(fromdate, todate); int[] to5 = new int[]{android.r.id.text1}; string[] from5 = new string[]{dblisthelper.account_name}; final simplecursoradapter adapter5 = new simplecursoradapter(getbasecontext(), android.r.layout.simple_list_item_1, cursor, from5, to5); adapter5.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinneraccountname.setadapter(adapter5); } } }); @override @deprecated protected dialog oncreatedialog ( int id){ switch (id) { case date_picker_id: return new datepickerdialog(this, datepickerlistener, year, month, day); case date_picker_id_1: return new datepickerdialog(this, datepickerlistener1, year, month, day); } return null; } private datepickerdialog.ondatesetlistener datepickerlistener = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int selectedyear, int selectedmonth, int selectedday) { etfromdate.settext(selectedday + " / " + (selectedmonth + 1) + " / " + selectedyear); } }; private datepickerdialog.ondatesetlistener datepickerlistener1 = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int selectedyear, int selectedmonth, int selectedday) { ettodate.settext(selectedday + " / " + (selectedmonth + 1) + " / " + selectedyear); } }; }
i think should date picker meant purpose only. spinner used more of finite choice. can use here need lot of reform code achieve same effect.
Comments
Post a Comment