xml - Searchview doesn't work on Android v6.0 -
well getting confuse one. create app have search feature, yesterday test on xiaomi redmi 2 android 4.4 , feature including search working smoothly. today test on friends nexus 5 android 6.1 , feature work except search feature.
when click search button, on xiaomi open searchbar user can type text keyword there on nexus showing keyboard , not searchbar. nothing happen if input text there.
please master me. don't know happen exactly.
thanks..
nb. activity contain search feature :
public class homeactivity extends appcompatactivity implements navigationdrawerfragment.navigationdrawercallbacks, byrentalfragment.categoryselectioncallbacks, bybrandfragment.categoryselectioncallbacks, bytypefragment.categoryselectioncallbacks, resultlistfragment.resultlistcallbacks, searchview.onquerytextlistener, adapterview.onitemclicklistener { private toolbar toolbar; tablayout tablayout; private viewpager viewpager; viewpageradapter viewpageradapter; private int navigationdepth = 0; private searchview msearchview; private list<string> suggestions; private string mcurrentsearchtext; private navigationdrawerfragment mnavigationdrawerfragment; private fragmentmanager fragmentmanager; private charsequence mtitle; private string subcategorytitle = null; private string resultlisttitle = null; private string detailviewtitle = null; private string searchquerytitle = null; private listview suggestionlistview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home); searchmanager searchmanager = (searchmanager) getsystemservice(context.search_service); searchableinfo searchableinfo = searchmanager.getsearchableinfo(getcomponentname()); toolbar = (toolbar)findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); tablayout = (tablayout)findviewbyid(r.id.tablayout); viewpager = (viewpager)findviewbyid(r.id.viewpager); viewpageradapter = new viewpageradapter(getsupportfragmentmanager()); viewpageradapter.addfragments(new byrentalfragment(),"rental"); viewpageradapter.addfragments(new bytypefragment(),"type"); viewpageradapter.addfragments(new bybrandfragment(), "brand"); viewpager.setadapter(viewpageradapter); tablayout.setupwithviewpager(viewpager); mnavigationdrawerfragment = (navigationdrawerfragment) getsupportfragmentmanager().findfragmentbyid(r.id.navigation_drawer); mtitle = gettitle(); mnavigationdrawerfragment.setup(r.id.navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout)); msearchview = (searchview) findviewbyid(r.id.searchview); msearchview.setsearchableinfo(searchableinfo); msearchview.setonquerytextlistener(this); msearchview.setinputtype(inputtype.type_class_text | inputtype.type_text_flag_cap_words); msearchview.setqueryhint(html.fromhtml("<small><small>" + "cari disini..."+ "</small></small>")); int searchplateid = msearchview.getcontext().getresources().getidentifier("android:id/search_plate", null, null); view searchplate = msearchview.findviewbyid(searchplateid); searchplate.setbackgroundcolor(color.transparent); int submitareaid = msearchview.getcontext().getresources().getidentifier("android:id/submit_area", null, null); view submitarea = msearchview.findviewbyid(submitareaid); submitarea.setbackgroundcolor(color.transparent); int searchimgicon = getresources().getidentifier("android:id/search_mag_icon", null, null); imageview searchimgview = (imageview) msearchview.findviewbyid(searchimgicon); searchimgview.setlayoutparams(new linearlayout.layoutparams(0, 0)); searchimgview.setvisibility(view.gone); int closebuttonid = msearchview.getcontext().getresources().getidentifier("android:id/search_close_btn", null, null); imageview closebutton = (imageview) msearchview.findviewbyid(closebuttonid); closebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { msearchview.setquery(null, false); utilmethods.hidesoftkeyboard(homeactivity.this); } }); suggestionlistview = (listview) findviewbyid(r.id.suggestionlistview); suggestionlistview.setonitemclicklistener(this); //initsearchfilter(); onnavigationdraweritemselected(0); } @override public void onbackpressed() { utilmethods.hidesoftkeyboard(this);//percobaan if(navigationdepth>=1){ navigationdepth--; fragmentmanager.popbackstack(); log.d("navdep", "backbutton " +navigationdepth ); }else if (navigationdepth == 0) { if(msearchview.getvisibility()==view.visible){ msearchview.setvisibility(view.gone); } } if(navigationdepth==0){ if(msearchview.getvisibility()==view.visible){ msearchview.setvisibility(view.gone); } if (tablayout.getvisibility() == view.gone) { tablayout.setvisibility(view.visible); } } } @override protected void onnewintent(intent intent) { setintent(intent); handleintent(intent); } private void handleintent(intent intent) { if (intent.action_search.equals(intent.getaction())) { string query = intent.getstringextra(searchmanager.query); msearchview.setquery(query, false); msearchview.clearfocus(); } } @override public void onnavigationdraweritemselected(int position) { if (msearchview.getvisibility() == view.visible) { hidesearchview(); } } public void restoreactionbar() { actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_standard); actionbar.setdisplayshowtitleenabled(true); if (navigationdepth == 0) { actionbar.settitle("rebil"); }else if (navigationdepth == 1) { actionbar.settitle(resultlisttitle); log.d("navdep", "restoreactionbar " + resultlisttitle); } else if (navigationdepth == 2) { actionbar.settitle(detailviewtitle); log.d("navdep", "restoreactionbar " + resultlisttitle); }else if (navigationdepth == 3) { actionbar.settitle(detailviewtitle); }else if (navigationdepth == 4) { actionbar.settitle(searchquerytitle); } } @override public boolean oncreateoptionsmenu(menu menu) { if (!mnavigationdrawerfragment.isdraweropen()) { getmenuinflater().inflate(r.menu.menu, menu); restoreactionbar(); return true; } return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { if (msearchview.isfocused()) { msearchview.setfocusable(false); } if (msearchview.getvisibility() == view.gone) { log.d("visible", "visible dude"); msearchview.setvisibility(view.visible); } hidesoftkeyboard(homeactivity.this); int id = item.getitemid(); switch (id) { case r.id.action_search: //if (!issearchfilershowing() && !mnavigationdrawerfragment.isdraweropen()) showsoftkeyboard(this); break; } return super.onoptionsitemselected(item); } private void showhidesearchview() { if (msearchview.getvisibility() == view.visible) { msearchview.setfocusable(false); msearchview.setvisibility(view.gone); hidesoftkeyboard(this); } else { msearchview.setvisibility(view.visible); msearchview.setquery("", false); msearchview.setfocusable(true); msearchview.requestfocus(); showsoftkeyboard(this); } } private void hidesearchview() { if (msearchview.getvisibility() == view.visible) { msearchview.setvisibility(view.gone); } hidesuggestionlist(); } private void hidesuggestionlist() { if (suggestionlistview != null && suggestionlistview.getvisibility() == view.visible) { suggestionlistview.setadapter(null); suggestionlistview.setvisibility(view.gone); } } @override public void oncategoryselected(string catid, string title ) { hidesearchview(); fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, resultlistfragment.newinstance(catid, title),"rl") .addtobackstack("catselect") .commit(); navigationdepth++; resultlisttitle = title; getsupportactionbar().settitle(title); log.d("navdep", "navselect : " + navigationdepth); if(tablayout.getvisibility()==view.visible) { tablayout.setvisibility(view.gone); } utilmethods.hidesoftkeyboard(this); } @override public void onresultitemselected(item itemdetails) { log.d("itemdetails", string.valueof(itemdetails)); log.d("itemdetails", string.valueof(itemdetails.getcarid())); fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, detailviewfragment.newinstance(itemdetails),"rl2") .addtobackstack("resultitemselect") .commit(); hidesearchview(); navigationdepth++; getsupportactionbar().settitle(itemdetails.gettitle()); detailviewtitle = itemdetails.gettitle(); log.d("navdep", "navselect : " + navigationdepth); actionbar actionbar = getsupportactionbar(); actionbar.settitle(itemdetails.gettitle()); utilmethods.hidesoftkeyboard(this); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { hidesearchview(); fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, resultlistfragment.newinstance("", suggestions.get(position))) .commit(); navigationdepth = 4; getsupportactionbar().settitle(suggestions.get(position)); searchquerytitle = suggestions.get(position); utilmethods.hidesoftkeyboard(this); } @override public boolean onquerytextsubmit(string query) { msearchview.clearfocus(); hidesearchview(); utilmethods.hidesoftkeyboard(this); fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, resultlistfragment.newinstance(query)) .addtobackstack("catselect") .commit(); navigationdepth++; if(tablayout.getvisibility()==view.visible) { tablayout.setvisibility(view.gone); } getsupportactionbar().settitle(query); resultlisttitle = query; searchquerytitle="true"; log.d("navdepquery",string.valueof(query)); log.d("navdep", "navselect : " + navigationdepth); return false; } @override public boolean onquerytextchange(string newtext) { if (newtext.length() == 0) { hidesuggestionlist(); utilmethods.hidesoftkeyboard(this); msearchview.clearfocus(); mcurrentsearchtext = null; return false; } if (!textutils.isempty(newtext)) { //getsearchsuggestions(newtext); mcurrentsearchtext = newtext; return true; } return false; } // search private void showsuggestions() { if (suggestions != null && suggestions.size() > 0 && !textutils.isempty(mcurrentsearchtext)) { if (suggestionlistview.getvisibility() == view.gone) { suggestionlistview.setvisibility(view.visible); } suggestionlistview.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, suggestions) { @override public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); textview textview = (textview) view.findviewbyid(android.r.id.text1); if (suggestions != null && suggestions.size() > 0 && !textutils.isempty(mcurrentsearchtext)) { string text = suggestions.get(position); int startindex = -1; int endindex = -1; if (!textutils.isempty(mcurrentsearchtext)) { startindex = text.tolowercase().indexof(mcurrentsearchtext.tolowercase()); endindex = (startindex + mcurrentsearchtext.length() < text.length()) ? startindex + mcurrentsearchtext.length() : text.length(); } if (startindex >= 0 && endindex >= 0) { spannablestringbuilder sb = new spannablestringbuilder(suggestions.get(position)); foregroundcolorspan fcs = new foregroundcolorspan(getresources().getcolor(r.color.green_text_color)); sb.setspan(fcs, startindex, endindex, spannable.span_inclusive_inclusive); stylespan bss = new stylespan(android.graphics.typeface.bold); sb.setspan(bss, startindex, endindex, spannable.span_inclusive_inclusive); textview.settext(sb); } else { textview.settext(suggestions.get(position)); } } return view; } }); } } private void getsearchsuggestions(string query) { string jsonstring = loadjsonfromasset(this, "get_suggestion_list"); try { jsonarray jsonarray = new jsonarray(jsonstring); int arraysize = jsonarray.length(); if (arraysize > 0) { suggestions = new arraylist<string>(); (int = 0; < arraysize; i++) { suggestions.add(jsonarray.getstring(i)); } } else { suggestions = null; } if (suggestions != null && suggestions.size() > 0) { runonuithread(new runnable() { @override public void run() { showsuggestions(); } }); } else { runonuithread(new runnable() { @override public void run() { hidesuggestionlist(); } }); } } catch (jsonexception e) { e.printstacktrace(); } } @override protected void onresume() { super.onresume(); } @override public boolean dispatchtouchevent(motionevent ev) { return super.dispatchtouchevent(ev); }
}
and xml homeactivity :
<android.support.v4.widget.drawerlayout xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.gook.rebill.activity.homeactivity"> <relativelayout android:id="@+id/relativelayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/view"> <include android:layout_height="wrap_content" android:layout_width="match_parent" layout="@layout/toolbar"/> <android.support.design.widget.tablayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tablayout" app:tabtextcolor="@color/hint_color_green" app:tabselectedtextcolor="@color/primary" app:tabmode="fixed" app:tabgravity="fill" android:fillviewport="false"> </android.support.design.widget.tablayout> </android.support.design.widget.appbarlayout> <android.support.v4.view.viewpager android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/viewpager" android:layout_below="@+id/view"> </android.support.v4.view.viewpager> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/view" /> <searchview android:id="@+id/searchview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_marginleft="@dimen/value_15dp" android:layout_marginright="@dimen/value_10dp" android:layout_margintop="@dimen/value_15dp" android:background="@drawable/search_bar" android:focusable="false" android:iconifiedbydefault="false" android:inputtype="textcapwords" android:visibility="visible" /> <listview android:id="@+id/suggestionlistview" android:layout_width="match_parent" android:layout_height="240dp" android:layout_alignleft="@+id/searchview" android:layout_alignright="@+id/searchview" android:layout_below="@+id/searchview" android:layout_margintop="2dp" android:background="@android:color/white" android:visibility="gone" /> <view android:id="@+id/blanklayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/filter_background_shadow_color" android:clickable="true" android:visibility="gone" /> </relativelayout> <fragment android:id="@+id/navigation_drawer" android:name="com.gook.rebill.fragment.navigationdrawerfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:layout_marginleft="@dimen/value_30dp" tools:layout="@layout/fragment_navigation_drawer" />
Comments
Post a Comment