database - Android listview item filter issue -
i have listview
work fine. have put edittext
@ top of listview
. want when enters letter "a", names starting "a" should appear in list . have try nothing happen please check code , tell me doing wrong.
this code of data list.
public class datalistactivity extends activity { listview listview; sqlitedatabase sqlitedatabase; fooddbhelper fooddbhelper; cursor cursor; listdataadapter listdataadapter; private button button1; listdataadapter dataadapter = null; button button; dataprovider dataprovider; arraylist<hashmap<string, string>> namesslist; edittext inputsearch; string search_name; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.data_list_layout); button1 = (button) findviewbyid(r.id.button1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //creating instance of popupmenu popupmenu popup = new popupmenu(datalistactivity.this, button1); //inflating popup using xml file popup.getmenuinflater() .inflate(r.menu.popup_menu, popup.getmenu()); //registering popup onmenuitemclicklistener popup.setonmenuitemclicklistener(new popupmenu.onmenuitemclicklistener() { public boolean onmenuitemclick(menuitem item) { alertdialog.builder a_builder = new alertdialog.builder(datalistactivity.this); a_builder.setmessage("do want close app !!!") .setcancelable(false) .setpositivebutton("yes",new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { intent intent = new intent(getapplicationcontext(), mainmenu.class); intent.addflags(intent.flag_activity_clear_top | intent.flag_activity_clear_task | intent.flag_activity_new_task); intent.putextra("exit", true); startactivity(intent); //finish(); } }) .setnegativebutton("no" , new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.cancel(); } }); alertdialog alert = a_builder.create(); alert.settitle("alert !!!"); alert.show(); // toast.maketext( // mainmenu.this, // "you clicked : " + item.gettitle(), // toast.length_short // ).show(); return true; } }); popup.show(); //showing popup menu } }); listview = (listview) findviewbyid(r.id.list_view); listdataadapter = new listdataadapter(getapplicationcontext(), r.layout.row_layout) { @override protected void showcheckedbutton(int position, boolean value) { // todo auto-generated method stub dataprovider item = (dataprovider) listdataadapter .getitem(position); log.i("", ""); item.setselected(value); button mybutton = (button) findviewbyid(r.id.findselected); mybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { stringbuffer responsetext = new stringbuffer(); responsetext .append("the following dishes selected...\n"); arraylist<dataprovider> list = listdataadapter .getselectedindexes(); int sum = 0; (int = 0; < list.size(); i++) { dataprovider dataprovider = list.get(i); sum = sum + dataprovider.getcalorie(); responsetext.append("\n" + dataprovider.getname() + " : " + dataprovider.getcalorie() + " kcal" ); } toast.maketext(getapplicationcontext(), ""+responsetext+"\n"+"................................." +"\n"+"total calories in menu : " +sum, toast.length_long).show(); } }); inputsearch = (edittext)findviewbyid(r.id.inputsearch); listview.setadapter(listdataadapter); inputsearch.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // when user changes text listdataadapter.getfilter().filter(cs); } @override public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } @override public void aftertextchanged(editable arg0) { // todo auto-generated method stub } }); } }; listview.setadapter(listdataadapter); fooddbhelper = new fooddbhelper(getapplicationcontext()); sqlitedatabase = fooddbhelper.getreadabledatabase(); cursor = fooddbhelper.getinformations(sqlitedatabase); if (cursor.movetofirst()) { { string name, quantity, fat, protein, sugar, vitamins; boolean selected = false; string names = null; integer calorie; name = cursor.getstring(0); quantity = cursor.getstring(1); calorie = integer.valueof(cursor.getstring(2)); fat = cursor.getstring(3); protein = cursor.getstring(4); sugar = cursor.getstring(5); vitamins = cursor.getstring(6); dataprovider dataprovider = new dataprovider(name, quantity, calorie, fat, protein, sugar, vitamins, names, selected); listdataadapter.add(dataprovider); } while (cursor.movetonext()); } listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string name = (string) ((textview) view .findviewbyid(r.id.text_dish_name)).gettext(); string quantity = (string) ((textview) view .findviewbyid(r.id.text_dish_quantity)).gettext(); string calorie = (string) ((textview) view .findviewbyid(r.id.text_dish_calorie)).gettext(); string fat = (string) ((textview) view .findviewbyid(r.id.text_dish_fat)).gettext(); string protein = (string) ((textview) view .findviewbyid(r.id.text_dish_protein)).gettext(); string sugar = (string) ((textview) view .findviewbyid(r.id.text_dish_sugar)).gettext(); string vitamins = (string) ((textview) view .findviewbyid(r.id.text_dish_vitamins)).gettext(); string.valueof(parent.getitematposition(position)); toast.maketext(getapplicationcontext(), "dish name : " + name, toast.length_short).show(); intent intent = new intent(getapplicationcontext(), detail.class); intent.putextra("dish name", name); intent.putextra("dish quantity", quantity); intent.putextra("dish calorie", calorie); intent.putextra("dish fat", fat); intent.putextra("dish protein", protein); intent.putextra("dish sugar", sugar); intent.putextra("dish vitamins", vitamins); startactivity(intent); } }); } public void gobackk(view view) { intent intent = new intent(this, mainmenu.class); startactivity(intent); } }
Comments
Post a Comment