Android Question Edittext cursor problem in customlistview

zetadan

Member
Licensed User
Longtime User
I am trying to implement the code from Erel's customlistview tutorial but I am having a strange problem. I replaced Erel's checkbox with an edittext. When the edittext is clicked and it gains focus, I do not get a cursor. The text will appear as soon as I type, but without the cursor it is impossible to know which edittext has focus. The following code is Erel's example without changes.
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    Dim chk As CheckBox
    chk.Initialize("chk")
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextSize = 16
    lbl.TextColor = Colors.White
    b.Text = "Click"
    p.AddView(lbl, 5dip, 2dip, 150dip, Height - 4dip) 'view #0
    p.AddView(b, 155dip, 2dip, 110dip, Height - 4dip) 'view #1
    p.AddView(chk, 280dip, 2dip, 50dip, Height - 4dip) 'view #2
    Return p
End Sub
And now my code with the edittext replacing the checkbox.
B4X:
Sub createlibitem(text As String, width As Int, height As Int) As Panel
    counter=counter + 1
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
'    Dim bpart As Button
    Dim bpart As Label
    bpart.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    bpart.Typeface = comic
    bpart.TextSize = 50
    bpart.TextColor=-1
    bpart.Color = Colors.ARGB(125,100,149,237)
    Dim partbox As EditText
    partbox.Initialize("boxes")
    partbox.Typeface = comic
    partbox.TextSize = 28
    partbox.Color = -1
    partbox.TextColor = -16777216
    partbox.SingleLine=True
    partbox.ForceDoneButton=True
    bpart.Gravity= Bit.OR(Gravity.CENTER_VERTICAL, Gravity.center_horizontal)
    bpart.text = text
    bpart.TextSize = 28
    bpart.TextColor=Colors.white
    p.AddView(bpart, 5dip, 0dip, 150dip, height)'-4dip) 'view #1
    p.AddView(partbox, 200dip, 2dip, 150dip, height-4dip) 'view #2
    Return p
End Sub
Does anyone know what is going on?

Dan
 

LucaMs

Expert
Licensed User
Longtime User
I don't know why (and now I do not want to investigate :D) excluding "partbox.Color = -1" the cursor becomes visible.

A small suggestion:
you might name the variables in a better way.

When I read "bpart" i must search for its type. lblPart or lblBPart is readily understandable.



[P.S. The Color property for EditText is not in the designer.

This means that it is inherited but probably it is not properly implemented and available.]


[I just found out that the reason is once again the TargetSDKVersion. :mad:
Change or delete it (manifest file) and you'll get your cursor :(]
 
Last edited:
Upvote 0
Top