android - How to check if view inside a dialog is focused? -
i have alert dialog box 2 searchview widgets this:
layout file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <searchview android:id="@+id/sourcesearchview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:iconifiedbydefault="false" > </searchview> <searchview android:id="@+id/destinationsearchview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:iconifiedbydefault="false"> </searchview> </linearlayout>
and in below code inflated layout dialog:
layoutinflater minflater = (layoutinflater)mcontext.getsystemservice(context.layout_inflater_service); view mview = minflater.inflate(r.layout.search_layout,null); msourcesearchview = (searchview)mview.findviewbyid(r.id.sourcesearchview); mdestinationsearchview = (searchview)mview.findviewbyid(r.id.destinationsearchview); msourcesearchview.setquery(mcurrentlocation, false); mbuilder = new alertdialog.builder(new contextthemewrapper(mcontext, android.r.style.theme_devicedefault_dialog)); mbuilder.setview(mview); malertdialog = mbuilder.create(); malertdialog.requestwindowfeature(window.feature_no_title); malertdialog.setcancelable(false);
my question: how check if 1 searchview focused , same other. tried returns null
malertdialog.getwindow().getcurrentfocus().isfocused()
you can utilize view.onfocuschangelistener
:
msourcesearchview.setonfocuschangelistener(new onfocuschangelistener() { @override public void onfocuschange(view view, boolean hasfocus) { if(hasfocus){ //do }else{ //something else } } });
if dont want utilize listener can use
msourcesearchview.isfocused();
the docs. hope helps :)
android android-alertdialog
No comments:
Post a Comment