Android Question Edittext with delete button

junglejet

Active Member
Licensed User
Longtime User
Is there a class out here which has a delete button (x) to the right of the text area, which appears when the area is filled by at least one character?

This is the standard with most if not all of the newer Android apps.

Thanks
Andy --
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the standard with most if not all of the newer Android apps.
Just checked several of the latest Google apps and didn't see it anywhere...

Anyway it should be quite simple to create such a class.

Here is an example to help you get started:
B4X:
'Class module
Sub Class_Globals
   Public edt As EditText
   Private btn As Button
End Sub

Public Sub Initialize (TargetModule As Object, EventName As String)

End Sub

Public Sub DesignerCreateView(Base As Panel, Lbl As Label, Props As Map)
   edt.Initialize("edt")
   btn.Initialize("btn")
   edt.TextSize = Lbl.TextSize
   edt.Text = Lbl.Text
   btn.Text = "Del"
   Base.AddView(edt, 0, 0, Base.Width - 50dip, Base.Height)
   Base.AddView(btn, Base.Width - 50dip, 0, 50dip, Base.Height)
   edt_TextChanged("", edt.Text)
End Sub

Sub btn_Click
   edt.Text = ""
End Sub
Sub edt_TextChanged (Old As String, New As String)
   btn.Enabled = New.Length > 0
End Sub

You can now add it with the designer as a custom view. Make sure to set the color to DEFAULT.
You should probably also change the button text to an image.
 
Upvote 0

junglejet

Active Member
Licensed User
Longtime User
Thanks Erel, I will try

It is typical for browsers (as Chrome) and apps that have search fields.
E.g. see investing.com app, this also has an icon to the left.

Best rgds
Andy
 
Upvote 0
Top