Android Question Search key on keyboard?

Discussion in 'Android Questions' started by ArminKH, Aug 14, 2015.

  1. ArminKH

    ArminKH Well-Known Member

    hi
    how is possible to use search button in keyboard?
    i have an edit text and i want to search for entered text in my txt file
    but i want to use keyboard search button
    is this possible?
    upload_2015-8-15_20-45-2.png
     
  2. stevel05

    stevel05 Expert Licensed User

    Have you tried using an Activity keypress sub?

    Code:
    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
        If KeyCode = KeyCodes.KEYCODE_SEARCH Then
            
    'Search pressed
            'your search code goes here
            Return True
        
    End If
    End Sub
     
    ArminKH likes this.
  3. ArminKH

    ArminKH Well-Known Member

    i can handle the search key event but how can i show search button(icon) for my edit text?
    please look at the above screen shot
     
  4. ArminKH

    ArminKH Well-Known Member

    @stevel05
    my problem solved by this hint
    http://stackoverflow.com/questions/23528644/edittext-ignores-the-imeactionlabel
    but as you can see in above link we should create a text box with xml
    but i want to use this for text boxes which are created by designer and also i want to use this for AppCombat Edittext
    is there any way to set android:imeOptions="actionSearch" by using java object to an edittext?
    this code not works
    Code:
    Dim r As Reflector
             r.Target = EditText1
             r.RunMethod2(
    "setImeOptions"4"java.lang.int")
     
    Last edited: Aug 14, 2015
  5. stevel05

    stevel05 Expert Licensed User

    I was just searching for the answer.

    To display a search icon instead of the return key, you can use:

    Code:
    Dim JO As JavaObject = EditText1
        JO.RunMethod(
    "setImeOptions",Array As Object(3))
    The key will then be treated as if you pressed the return key.

    In addition, you can set the onEditorActionListener to respond to the key.

    Code:
    Dim O As Object = JO.CreateEvent("android.widget.TextView.OnEditorActionListener","Search",Null)
        JO.RunMethod(
    "setOnEditorActionListener",Array As Object(O))
    Which will call the sub:

    Code:
    Sub Search_Event(MethodName As String,Args() As Object) As Object
        
    Log(MethodName & " called")
        
    Return True
    End Sub
    When it is pressed, return False instead of true to close the keyboard.
     
    ArminKH likes this.
  6. ArminKH

    ArminKH Well-Known Member

    thank u steve but this is still not works on my device
    Code:
    Dim EditText1 As EditText
                EditText1.Initialize(
    "EditText1")
                
    Activity.AddView(EditText1 , 0,0,100dip,50dip)
                
    Dim JO As JavaObject = EditText1
                JO.RunMethod(
    "setImeOptions",Array As Object(3))
     
  7. ArminKH

    ArminKH Well-Known Member

    @stevel05
    Solved
    the Edit Text must be single line
    now this code works
    Code:
    Dim EditText1 As EditText
                EditText1.Initialize(
    "EditText1")
                
    Activity.AddView(EditText1 , 0,0,100dip,50dip)
                EditText1.SingleLine = 
    True
               
                
    Dim JO As JavaObject = EditText1
                    JO.RunMethod(
    "setImeOptions",Array As Object(3))
    thanx for your help;)
     
  8. Ju Yang

    Ju Yang Active Member Licensed User

    "actionDone"? Array As Object(?) ? I tested 0-6 but didn't have any effect.
    thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice