Android Question AutoCompleteEditText with INPUT_TYPE_DECIMAL_NUMBERS

peacemaker

Expert
Licensed User
Longtime User
HI, All

Anyone tried to use the AutoCompleteEditText view with the list of decimal values ?
Say, 0.5, 1, 1.5, 2, 2.5 ......
So the aim is to fastly choose from list or enter (say 3.35) manually.
How to show the filtered suggestion list ? Rebuild the list every TextChanged ?

If to do so:
B4X:
Sub txtQty_TextChanged (Old As String, New As String)
    Dim L As List
    L.Initialize
    Dim j As Float
    For j = 0.5 To 10 Step 0.5
        Dim a As String = j
        If a.Contains(New) Then
            L.Add(a)
        End If
    Next
    If L.Size > 0 Then
        txtQty.SetItems(L)
        txtQty.ShowDropDown
    End If
End Sub

there is a error after ItemClick:
B4X:
** Activity (neworder) Resume **
java.lang.IndexOutOfBoundsException: Index: 15, Size: 2
    at java.util.ArrayList.get(ArrayList.java:437)
    at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:385)
    at anywheresoftware.b4a.objects.AutoCompleteEditTextWrapper$1.onItemClick(AutoCompleteEditTextWrapper.java:121)
    at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:1017)
    at android.widget.AutoCompleteTextView.-wrap1(Unknown Source:0)
    at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1313)
    at android.widget.AdapterView.performItemClick(AdapterView.java:318)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127)
    at android.widget.AbsListView$3.run(AbsListView.java:4042)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Note that SearchView is not enough - the manual input result is also needed.
Also note that suggest list cannot hold Float values, just compatible with CharSequence types... :(
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Yes.
I have added
B4X:
Sub getText As String
    Return et.Text
End Sub

But found a new trouble that the SearchView cannot just be placed at the activity bottom, like narrow (AutoComplete)EditText.
 
Upvote 0
Top