Android Question IME.Showkeyboard

jimseng

Active Member
Licensed User
Longtime User
Hello
I have a transparent panel placed over an edittext in an xcustomlistview. I am doing this in order to achieve a click and long click associated with the edittext beneath. This might not be the right way of going about things but it is where I am at the moment. When I click on the panel I request the focus of the edittext and show the keyboard using IME.showkeyboard. I then place the cursor at the end of the text with "selectionstart". I was wondering if there was a way to get the keyboard to behave as if it was a normal edittext, i.e being able to place the cursor with a click, or to put it another way, have a moveable cursor with the "android teardrop".
Thanks
 

jimseng

Active Member
Licensed User
Longtime User
I couldn't see a long click event for the edittext (it's a few years since I have have done anything with B4A, I haven't kept up) so as a workaround I placed a transparent panel over the top of the edittext in my layout. When I click on the panel I set the focus of the edittext beneath and place the cursor at the end and show the keyboard. If I want, for instance, to correct a spelling mistake I have to use the delete key of the keyboard rather than have the option of moving the cursor around. To be clear, I have a xcustomlistview which may have several entries already. It is for when I want to edit one of the entries. Maybe this screen shot will help. At the top is an edittext with the cursor moved to somewhere in the body of the text. I can't get the same behaviour in the customlistview below When I set the focus of the editttext and show the keyboard.
c.jpg

B4X:
Private Sub Panel1_Click

    Dim index As Int = CLV2.GetItemFromView(Sender)
    Dim pnl As B4XView = CLV2.GetPanel(index)
    Dim txtItm As B4XView = pnl.GetView(0) ' edittext is the first view in the layout.
    Dim ime1 As IME
    txtItm.RequestFocus
    ime1.ShowKeyboard(txtItm)
    txtItm.SelectionStart = txtItm.Text.Length 'places the cursor at the end of the text
End Sub
 

Attachments

  • c1.jpg
    c1.jpg
    25 KB · Views: 183
Upvote 0

Mahares

Expert
Licensed User
Longtime User
as a workaround I placed a transparent panel over the top of the edittext in my layout
I don't think you need a transparent panel over the edittext. Get rid of it. Use the EnterPressed event of the edittext:
B4X:
Sub txtItm_EnterPressed
     Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As B4XView = clv2.GetPanel(index)
    Dim e As B4XView = pnl.GetView(0) ' edittext is the first view in the layout.
    e.SelectionStart = e.Text.Length 'places the cursor at the end of the text
End Sub
If I did not understand your post question, please ditch this answer and request more help.
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
HI.
I am not very good at making myself clear! It was because I wanted a long click event for each edittext in the cutomlistview. I have worked it out though. The issue was that although I was requesting the focus the edittext, the panel was still on top blocking the edittext. By setting the panels visibility to false it works as I expect.
Thanks for your respnonses.
p.s. Is there a way of creating a long click event for the edittext?
 
Upvote 0
Top