EditText with Custom KeyPad

SeaCay

Member
Licensed User
Longtime User
Hello All,

Android Version 2.3.4

I want to have certain but not all EditText views to have a custom keypad.

My construnction is

B4X:
Sub makeEdit(Id As Int)
  Dim edtHeight As Int
  Dim eIME As IME 
  Dim anEdit As EditText
  
    edtHeight = 60

   make_Quest_Label(Id)
    FBEdits(edtKount).Initialize("Edit")
   anEdit = FBEdits(edtKount)
   checkPanelHeight(edtHeight) 'Checks/Adjusts to ensure that parent will display the view fully
   
    FBPanels(pnlKount - 1).AddView(FBEdits(edtKount), EditX, LastY, TEXTWIDTH, edtHeight)
   FBEdits(edtKount).Tag = Id
   FBEdits(edtKount).Text = "0"
  
    If (FldType(Id) = "FLOAT") OR (FldType(Id) = "INTEGER") Then
      eIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_NUMBERS, "0123456789.,-")
    End If


   FBEdits(edtKount).TextColor = Colors.RGB(128, 128, 0)

   LastY = FBEdits(edtKount).Top + FBEdits(edtKount).Height + FreeHeight
   
   edtKount = edtKount + 1
End Sub
You can see that I am using IME to define the active buttons for the KeyPad
Note: I know that integers do not have decimals so the code is supplied for ease of digestion

My Focus Event code is

B4X:
Sub Edit_FocusChanged (HasFocus As Boolean)
  Dim anEdit As EditText
  Dim FBIME As IME
  
    anEdit = Sender
    If (HasFocus = True) Then
      FBIME.ShowKeyboard(anEdit)
    Else
     FBIME.HideKeyboard
   End If
End Sub

From the FocusChanged event, the keyboard is made visible by the IME call.

However I only get as basic numeric keypad with ".,-" buttons disabled.

Please can someone tell me where I am going wrong?

Regards and Thanks

SeaCay
 

klaus

Expert
Licensed User
Longtime User
This line
B4X:
eIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_NUMBERS, "0123456789.,-")
must be
B4X:
eIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_DECIMAL_NUMBERS, "0123456789.,-")
INPUT_TYPE_NUMBERS accepts only numbers.

Best regards.
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Klaus,

Thank you for your reply.

I implemented your solution but I regret to advise that it makes no difference. The pop-up keypad is identical to my orginal method.

regards

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello Klaus,

Thank you for your continued interest in my issue. I appreciate your replies.

To answer your recent question, yes the keypad that pops-up when I user either INPUT_TYPE_NUMBERS or INPUT_TYPE_DECIMAL_NUMBERS is the same.

You are correct when you say the ".,-" keys are still disabled.

I feel that I am missing a step in the process. The way I see it is that the code

B4X:
eIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_NUMBERS, "0123456789.,-")

defines and assigns a custom keyboard to a specific View, in this case a TextEdit.

And the code in the FocusChanged Event

B4X:
FBIME.ShowKeyboard(anEdit)

calls and displays the custom keypad.

Is there anything else I need to do?

regards and thanks

SeaCay
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
Hello all,

As a testing premise I removed the "3" from

B4X:
FBIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_NUMBERS, "0123456789.,-")

so I had

B4X:
FBIME.SetCustomFilter(anEdit, anEdit.INPUT_TYPE_NUMBERS, "012456789.,-")

When I ran the code the pop-up keyboard had a "3" enabled and visible.

I can not figure this out.

All I want is a numeric key board with the ability to have decimal values and negative numbers.

I appreciate all constructive advice. Thanks for your thoughts.

regards

SeaCay
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
First:
You are correct when you say the ".,-" keys are still disabled.
I didn't say that the given keys were disabled !
I asked you if you were sure that these keys were disabled which is not the same.

I dont know how you tested your program ?
This code below works fine on my Nexus One !
It works with both INPUT_TYPE_NUMBERS and INPUT_TYPE_DECIMAL_NUMBERS.
B4X:
Sub Globals
    Dim edt1, edt2 As EditText
    Dim ime1 As IME
End Sub

Sub Activity_Create(FirstTime As Boolean)
    edt1.Initialize("edt")
    edt2.Initialize("edt")
    Activity.AddView(edt1, 20dip, 20dip, 150dip, 50dip) 
    Activity.AddView(edt2, 20dip, 90dip, 150dip, 50dip) 
    ime1.SetCustomFilter(edt1, edt1.INPUT_TYPE_NUMBERS, "012456789.,-")
    ime1.SetCustomFilter(edt2, edt2.INPUT_TYPE_DECIMAL_NUMBERS, "012456789.,-")
End Sub

Sub edt_FocusChanged (HasFocus As Boolean)
    Dim edt As EditText
    
    edt = Sender
  
    If (HasFocus = True) Then
        ime1.ShowKeyboard(edt)
    Else
        ime1.HideKeyboard
    End If
End Sub
Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tested Klaus 's code and it works. Both text views do the same thing. They accept any one of these: 012456789.,-
The number 3 is refused. The problem I found with IME is that you can insert more one period(.) and more than one minus sign(-) and more than one comma(,) as per this code, which renders numbers useless.
 
Upvote 0

SeaCay

Member
Licensed User
Longtime User
It seems that the problem was with the implementation of Gingerbread on the device I was using at the time I first raise the issue. The problem went away when I tried the same code on a Galaxy Note.

My thanks to those who replied.

regards

SeaCay
 
Upvote 0
Top