Android Question many view use one and the same class module

acj200301

Member
'i have a question about class and list and many view ,


'What to deal with is , many EditText placed on form ,

'if the value(text) of any EditText is changed then the backcolor of it will be changed ,

'i used class module in vb , it can fulfil the task , the following is code
the followring code is in form1 ,

B4X:
'  code in form1 of vb ,
'
Private collec_1 As New Collection


Private Sub Form_Initialize()

''┌一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一┐
    Set cla_1 = New Class1:       Set cla_1.butt_of_class = Form1.Cmd_1:      collec_1.Add cla_1   '
    Set cla_1 = New Class1:       Set cla_1.butt_of_class = Form1.Cmd_2:      collec_1.Add cla_1

    Set cla_1 = New Class1:       Set cla_1.butt_of_class = Form1.Cmd_3:      collec_1.Add cla_1
''└一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一┘

'┌一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一┐
    Set cla_1 = New Class1:       Set cla_1.TEXT_of_class = Form1.Text1:      collec_1.Add cla_1
  
    Set cla_1 = New Class1:       Set cla_1.TEXT_of_class = Form1.Text2:      collec_1.Add cla_1
  
    Set cla_1 = New Class1:       Set cla_1.TEXT_of_class = Form1.Text3:      collec_1.Add cla_1
'└一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一┘


Me.WindowState = 2
End Sub

the followring code is in class1 ,

B4X:
Public WithEvents butt_of_class As CommandButton  '

Public WithEvents TEXT_of_class As TextBox

                                           Public v_numbers_of_times  As Integer
'


Private Sub TEXT_of_class_Change()

                                           v_numbers_of_times = v_numbers_of_times + 1
                                          
If v_numbers_of_times Mod 2 = 0 Then TEXT_of_class.BackColor = vbRed


If v_numbers_of_times Mod 2 = 1 Then TEXT_of_class.BackColor = vbBlue

End Sub

' 一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一

' in b4a , i do not know how to this , so ,i read some sample code , and i write some code ,such as following ,

' i do not know how to trigger sub edittext_in_class_TextChanged in class , so ,i write following to try ,


' For i = 0 To L_1_LIST_1.Size - 1
'
' CallSub(L_1_LIST_1.Get(i), "edittext_in_class_TextChanged")
' Next

' but , tip is layer not available ,

' of course ,EditText1 EditText1 EditText3 is not changed , failed to be changed ,

' 一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一

the following is code in main activity ,

B4X:
Sub Globals
    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
'                                                      Private Button1 As Button
    
    Public L_1_LIST_1 As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume
    
    L_1_LIST_1.Initialize
    
    Dim cla_1 As c_l_value_change
    
    cla_1.Initialize(L_1_LIST_1  , 1, 11, EditText1)   
    '一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一

    Dim cla_2 As c_l_value_change
    
    cla_2.Initialize(L_1_LIST_1  , 2, 22, EditText2)
    '一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
    Dim cla_3 As c_l_value_change
    cla_3.Initialize(L_1_LIST_1  , 3, 33, EditText3)
    '一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
 
    ' i do not know how to trigger edittext_in_class_TextChanged in class , so ,i write following to try ,
    
'    but , tip is layer not available ,
    Private i As Int
    
    For i = 0 To L_1_LIST_1.Size - 1
        
        CallSub(L_1_LIST_1.Get(i), "edittext_in_class_TextChanged")
    Next
''    Activity.Invalidate
    
    ' : cla_1.Old=1: cla_1.new = 3:  cla_1.edittext_in_class = EditText1: L_1_LIST_1.Add(cla_1): cla_1.edittext_in_class_TextChanged
        
'    cla_1.Old=1: cla_1.new = 3: cla_2.edittext_in_class = EditText2  : L_1_LIST_1.Add(cla_1)
    
'    cla_1.Old=1: cla_1.new = 3: cla_3.edittext_in_class = EditText1:L_1_LIST_1.Add(cla_3)
End Sub


the following is code in c_l_value_change ,wihich is a standard calss module,

B4X:
#Event: TextChanged
#Event: click

#Event: edittext_in_class_TextChanged
#Event: _click
Sub Class_Globals
    Public New_in_class, Old_in_class As Int
    Public  edittext_in_class As EditText
End Sub
 
Sub Initialize (L_1_LIST_1 As List, Old As Int, New As Int, view_1 As View)

    L_1_LIST_1.Add(Me)   '
    
      New_in_class = New
      
    edittext_in_class.Initialize("TextChanged")
End Sub


Sub edittext_in_class_TextChanged
    
    edittext_in_class.text = New_in_class
    
End Sub

i do not know how to do ,so i post the code ,

thank you ,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code doesn't handle the activity life cycle correctly. Either waste your time with fixing it or switch to B4XPages.
The vb6 code is not relevant.

1. The event will be raised in the module where the views were loaded.
2. While it is not the only possible option, it will be simplest to create the EditText inside the class. This way the event will be raised in the class.
 
Upvote 0

acj200301

Member
thanks ,
yeah , it spend me 2 days in reading sample code and trying to writing ,

' 一一一一
you tell me in your message , While it is not the only possible option, it will be simplest to create the EditText inside the class. This way the event will be raised in the class.

wether it mean ? maybe other way can do this ,but creating the EditText inside the class is simplest ,

ok ,

creating the EditText inside the class

how can i create the EditText inside the class ?

in standard class? in custom view ?

if , in standard class

whether the code is like the following,

Private panel_1 As Panel : Private inner_View As EditText : Dim r__1 As Reflector

panel_1.Initialize("") : panel_1.Color = Colors.Transparent
Activity.AddView(panel_1, v__1.Left, v__1.Top, v__1.Width, v__1.Height)

Private Sub panel_1_Touch

,,,,,

end sub

or , do not use panel ,do not use Reflector , use sub inner_View_textchanged , use #Event: textchanged ,

but ,wether #Event: textchanged can be used in standard class ?


if , in custom view

wether it is needed that i create view in view_desinger ?

thank you ,

after this , i make some experiment to use "sub inner_View_textchanged" , use #Event: textchanged ,but failed
 
Upvote 0
Top