Android Question edittext custom view

Kiran Raotole

Active Member
Licensed User
Hii experts,
I'm new to b4a custom view, so please help me.

I'm trying to create edittext custom view, add I want to add textchange event
my code is :
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    edittext.Initialize("")
    Base.AddView(edittext,0,0,Base.Width,Base.Height)
End Sub


Private Sub edittext_TextChanged(old As String,new As String)
    Log("text  changed event working")
    If SubExists(mCallBack,mEventName &  "_TextChanged") Then
        CallSub(mCallBack,mEventName & "_TextChanged")
    End If
End Sub

whats wrong?
 

udg

Expert
Licensed User
Longtime User
Have a look at the EditText definition (in particular at the Initialize method).
Initialize (EventName As String)
Initializes the view and sets the subs that will handle the events.
Views added with the designer should NOT be initialized. These views are initialized when the layout is loaded.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It is a his custom view.

You have to declare the EditText (choose a better name, not the one of the class - like EditText1, at least) and pass an event name to its initialization, to be used in the custom view internal event.

B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    Dim EditText1 As EditText
    EditText1.Initialize("EditText1")
    Base.AddView(EditText1,0,0,Base.Width,Base.Height)
End Sub

B4X:
Private Sub EditText1_TextChanged(old As String,new As String)
    Log("text  changed event working")
    If SubExists(mCallBack,mEventName &  "_TextChanged") Then
        '    CallSub(mCallBack,mEventName & "_TextChanged")
        '  use CallSub2 or CallSub3 to pass parameters
        CallSub3(mCallBack, mEventName & "_TextChanged", old, new)
    End If
End Sub
 
Upvote 0

Kiran Raotole

Active Member
Licensed User
thanks LucaMs
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…