ajuda com classe

andre.astafieff

Member
Licensed User
Longtime User
help with class

Hello!

Could anyone help me with creating a class?
I need to create a component consists of three objects, two pictures and one text field, where clicking the + or - the value of the text field is incremented or decremented.

I need the class to not have to keep repeating the components on a screen





Olá!

Alguém poderia me ajudar com a criação de uma classe?
Preciso criar um componente composto por 3 objetos, sendo duas imagens e um campo texto, onde ao clicar no + ou - o valor do campo texto é incrementado ou reduzido.

Preciso da classe para não ter que ficar repetindo os componentes em uma tela. :BangHead::BangHead::BangHead:
 

Attachments

  • download.jpg
    download.jpg
    24.8 KB · Views: 161
Last edited:

andre.astafieff

Member
Licensed User
Longtime User
Have a look at the User's Guide Edition 1.3 chapter 10 Class modules.

Best regards.


Thanks Klaus :sign0188:

I was impressed with the ease of creating the library, the following code will save me some time programming ...

ps: it is still a test version of the features ...

B4X:
'class BtnSoma
Sub Class_Globals
   Private ImgMais As ImageView 
   Private ImgMenos As ImageView 
   Private ValorSoma As EditText 
   Private ValorTotal As Int 
   Private BordaC As Panel 
   Private Callback As Object 
   Private Left, Top, Width, Height As Float
End Sub

Public Sub Initialize(CallbackModule As Object, Parent As Object, Direita As Float, Topo As Float  )

   Callback = CallbackModule
   
   BordaC.Initialize("BordaC")
   ImgMais.Initialize("ImgMais")
   ImgMenos.Initialize("ImgMenos")
   ValorSoma.Initialize("ValorSoma") 

   ValorSoma.InputType = ValorSoma.INPUT_TYPE_NUMBERS 
   ValorSoma.Text = 0
   
   ValorSoma.TextSize = 10
   
   
   ImgMenos.SetBackgroundImage(LoadBitmap(File.DirAssets,"menosico.png"))
   ImgMais.SetBackgroundImage(LoadBitmap(File.DirAssets,"maisico.png"))
   
   BordaC.AddView(ImgMenos,0,0,48,48)
   BordaC.AddView(ValorSoma,48,0,48,44)
   BordaC.AddView(ImgMais,96,0,48,48)
   
   Width = 155
   Height = 50

   If Parent Is Activity Then
      Dim act As Activity
      act = Parent
      Left = Direita   
      Top = Topo
      act.AddView(BordaC, Left, Top, Width, Height)
   Else 
      Dim pnlp As Panel
      pnlp = Parent
      Left = Direita      
      Top = Topo
      pnlp.AddView(BordaC, Left, Top, Width, Height)
   End If

End Sub

Private Sub ImgMais_Click
   ValorSoma.Text = NumberFormat2(ValorSoma.Text + 1,0,2,2,False)
   ValorTotal = ValorSoma.Text
End Sub
Private Sub ImgMenos_Click
   If ValorSoma.Text > 0 Then
      ValorSoma.Text = NumberFormat2(ValorSoma.Text - 1,0,2,2,False)
      ValorTotal = ValorSoma.Text
   End If
End Sub
Public Sub GetValue As Int 
   Return ValorTotal
End Sub
 
Upvote 0
Top