android - Filtering ListView using the EditText inside the ActionBar -
i want carry out functionality same in link below:
http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/
however example uses normal edittext , don't want waste screen real estate. therefore i'd prefer use edittext positioned inside actionbar, same used normal searching. how can access edittext in order place textwatcher on it? what's id it?
i want add textwatcher:
edittext.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence cs, int arg1, int arg2, int arg3) { // when user changed text mainactivity.this.adapter.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 } });
thanks in advance!
you can use search menu item. go code below use this
edittext search; public boolean oncreateoptionsmenu(com.actionbarsherlock.view.menu menu) { layoutinflater inflater = (layoutinflater)this.getsystemservice(context.layout_inflater_service); relativelayout rl =(relativelayout)inflater.inflate(r.layout.search_text, null); search=(edittext)rl.getchildat(0); search.addtextchangedlistener(filtertextwatcher); menu.add(0, 1, 1, r.string.inlinesearch).seticon(r.drawable.action_search).setactionview(rl).setshowasa ction(menuitem.s how_as_action_always); return super.oncreateoptionsmenu(menu); } private textwatcher filtertextwatcher = new textwatcher() { public void aftertextchanged(editable s) { log.e("textwatcher","after"); } public void beforetextchanged(charsequence s, int start, int count, int after) { log.e("textwatcher","before"); } public void ontextchanged(charsequence s, int start, int before, int count) { log.e("textwatcher","ontext"); } };
and layout search :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="fill_horizontal" > <edittext android:id="@+id/search_text" style="@style/edittextholodark" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginleft="4dip" android:imeactionid="1337" android:imeoptions="actiondone" android:inputtype="textcapcharacters|textnosuggestions" android:singleline="true" android:hint="search" android:textstyle="bold" android:drawableleft="@drawable/action_search" /> </relativelayout>
let me know helpful or not.?
Comments
Post a Comment