Android Question Custom Filter for keyboard not working!!

badal405

Member
Licensed User
Longtime User
Hi,
I have a panel with 15 EditText and I want to set a custom filter for the keyboard. So instead of manually written for every EditText I just write a method which should solve my purpose but unfortunately it's not working at all!! I really don't understand where is mistake.
Would someone help me in this regards.
Thanks in advance.

B4X:
Public Sub RemoveSpecialChar(srcPanel As Panel)
    Dim kb As IME
    Dim answ As Int
    'srcPanel.Initialize("")
    For answ=0 To srcPanel.NumberOfViews-1   
        If srcPanel.GetView(answ) Is EditText Then
            Dim txt As EditText
            txt=srcPanel.GetView(answ)
            If txt.InputType = txt.INPUT_TYPE_TEXT  Then
                kb.Initialize("")
                kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 ")

            End If
        End If
    Next

End Sub
 

imbault

Well-Known Member
Licensed User
Longtime User
In your code, select the line
B4X:
                kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 ")
at the left of the line (left of the line number of the iDE), just click, you should see a red dot, it's the breakpoint.


Then run in Debug mode, and see is this line is skipped or not.
 
Last edited:
Upvote 0

badal405

Member
Licensed User
Longtime User
In your code, select the line
B4X:
                kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 ")
at the left of the line (left of the line number of the iDE), just click, you should see a red dot, it's the breakpoint.


Then run in Debug mode, and see is this line is skipped or not.

I run in Debug mode before and it didn't skip. Because after this
B4X:
kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 ")
I printed log('') and it has printed the log. That means this line has not skipped.
I am calling the function from Activity_Create
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("ktc")
    fn.GPS1.Initialize("GPS1")
    sv.Visible=True

    pnlDataSetting.RemoveView
    sv.Panel.Height=pnlDataSetting.Height
    sv.Panel.AddView(pnlDataSetting,0,0,sv.Width,sv.Panel.Height)

    fn.DatabaseMount
    LoadSpinnerData
  
    fn.RemoveSpecialChar(Panel1)
    fn.MakeKeyboardUppercase(Panel1)
  
End Sub
even
B4X:
fn.MakeKeyboardUppercase(Panel1)
function also not working.

Regards.
 
Upvote 0

badal405

Member
Licensed User
Longtime User
B4X:
Public Sub MakeKeyboardUppercase(srcPanel As Panel)
    Dim answ As Int
   
    For answ=0 To srcPanel.NumberOfViews-1   
        If srcPanel.GetView(answ) Is EditText Then
            Dim txt As EditText
            txt=srcPanel.GetView(answ)
            If txt.InputType = txt.INPUT_TYPE_TEXT  Then
                'Uppercase
                txt.InputType = Bit.OR(txt.INPUT_TYPE_TEXT, 4096)' to make keyboard uppercase
            End If
        End If
    Next

End Sub
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
You are setting the InputType a second time in MakeKeyboardUppercase, this discards the filter set in RemoveSpecialChar.

If you need uppercase, you just have to set :
B4X:
kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNM1234567890 ")

and not calling in your Activity_Create
B4X:
fn.MakeKeyboardUppercase
 
Last edited:
Upvote 0

badal405

Member
Licensed User
Longtime User
But now I noticed another thing. Out of my 15 EditText most of them are Text and only few are Number. So I only need to make soft keyboard to Uppercase and remove special character for those EditText whose input type only Text. To do so I added the condition like
B4X:
            If txt.InputType = txt.INPUT_TYPE_TEXT  Then
                kb.Initialize("")
                kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNM1234567890 ")
                Log("not skeep")
                'txt.InputType = Bit.OR(txt.INPUT_TYPE_TEXT, 4096)' to make keyboard uppercase
                'EditText1.InputType = Bit.OR(EditText1.INPUT_TYPE_TEXT, 8192)' to make keyboard uppercase
            Else
                Log("not text: " & txt.InputType)
            End If
But after I debug again now I found most of the cursor step are going to Else condition not to If condition!!!! Did I made any mistake on
B4X:
If txt.InputType = txt.INPUT_TYPE_TEXT  Then
condition?
Regards.
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
Based on txt.INPUT_TYPE_TEXT What says the log in:
B4X:
Log("not text: " & txt.InputType)

You could try the opposite, condition on txt.INPUT_TYPE_NUMBERS
 
Last edited:
Upvote 0

badal405

Member
Licensed User
Longtime User
You could try with your first condition only, which filters EditText views, if it's not enought, put something in tag
B4X:
If srcPanel.GetView(answ) Is EditText Then
But in that case all my Edittext which I set input type Number in design mode will change to Text right? But I want only those EditText whose input type only Text.
 
Upvote 0

badal405

Member
Licensed User
Longtime User
I changed my answer, see Post #9
But I want to remove the special character and in the same time make keyboard layout uppercase. I am facing the problem when I am calling MakeKeyboardUppercase and RemoveSpecialChar function together, one discards the filter set to other one and vise versa.
Is there anyway to do this? Please advice.
Regards.
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
So why not keeping
B4X:
                kb.SetCustomFilter(txt, txt.INPUT_TYPE_TEXT, "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 ")

Then adding your EditText a validation routine which uppercases them like:
B4X:
Sub EditText1_FocusChanged (HasFocus As Boolean)
    Dim txt=Sender As EditText
    txt.Text=txt.Text.ToUpperCase
End Sub
 
Upvote 0
Top