Android Question Set focus in ACSearchView from button

kris A

Member
Licensed User
Hi all,
i want to set focus in ACSearchView from button click,
is there any idea?

Thanks.
 

Brandsum

Well-Known Member
Licensed User
Try this (Not tested)
B4X:
    Dim r As Reflector
r.Target = SearchBar
r.Target = r.GetField("mSearchView")
Dim t As EditText = r.RunMethod4("findViewById", Array As Object(r.GetStaticField("android.support.v7.appcompat" & ".R$" & "id", "search_src_text")), Array As String("java.lang.int"))
t.RequestFocus
 

kris A

Member
Licensed User
Try this (Not tested)
B4X:
    Dim r As Reflector
r.Target = SearchBar
r.Target = r.GetField("mSearchView")
Dim t As EditText = r.RunMethod4("findViewById", Array As Object(r.GetStaticField("android.support.v7.appcompat" & ".R$" & "id", "search_src_text")), Array As String("java.lang.int"))
t.RequestFocus
Hi brandsum,
thanks for the help,
I've tried your code but nothing happen
Here my code,
B4X:
Dim sv As ACSearchView
Dim si As ACMenuItem
Dim btnSearch As Button

Sub Activity_CreateMenu(Menu As ACMenu)
    sv.Initialize2("Search", sv.THEME_DARK)
    sv.IconifiedByDefault = True
    Menu.Clear
    Dim xml As XmlLayoutBuilder
    si = Menu.Add2(1, 1, "productSearch", xml.GetDrawable("ic_search_white_24dp"))
    si.SearchView = sv
End Sub

Sub btnSearch_Click
End Sub
i wanna give sv a focus (without si clicked), when user click btnSearch
thanks before.
 
Last edited:
Top