Android Question scrollview change another label with click label

harry2017

Member
Licensed User
I want change value of jml label if I click label tambah(+) or label kurang (-)on scrollview

I have been searching all thread never get the solution ...
I need ..if I click tambah_click then jml(label) change to 1 and 2, ..next
thanks before ,,,sorry of my bad english
B4X:
Sub Process_Globals
    Public sql As SQL
End Sub

Sub Globals
    Dim IE As RSImageEffects
    'Dim Lista_botones As List
    Dim listtombol As List
    Dim Color_Boton As Int = Colors.ARGB(255, 0, 0, 160)
    'Dim alto_boton As Int = 45%x + 50dip 'los 50 dip es el espacio donde irá el texto del botón
    'Dim alto_boton As Int = 10%x + 50dip 'los 50 dip es el espacio donde irá el texto del botón atur tinggi tombol
    Dim tinggi_tombol As Int = 20%x '+ 10dip 'los 50 dip es el espacio donde irá el texto del botón atur tinggi tombol
    'Dim ancho_boton As Int = 20%x 'atur lebar tombol
    Dim lebar_tombol As Int = 20%x 'atur lebar tombol
    'Dim columnas As Int = 4
    Dim kolom As Int = 2
    'Dim separacion As Int
    Dim spasi As Int
    'Dim intTotalBotones As Int
    Dim intTotalTombol As Int


    'Private edTitle As ACEditText

'    Dim demo As ShoppingView
    'Dim harga As Label
    'Dim BottomNavigation1 As BottomNavigation
  
    Dim label1 As Label
    Dim label2 As Label
    Dim label3 As Label
    Dim tambah As Label
    Dim jml As Label
'    Private SV As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("cariobat")
    preparaDB
  
    Dim SV As ScrollView
    SV.Initialize(100dip) '100dip - Tamaño del panel provisional ' ukuran scroowiew
    SV.Panel.Color=Colors.Magenta
  
    Activity.AddView(SV, 0, 12%y, 100%x, 100%y)' ukuran tampilan scrollview
  
    listtombol = DBUTILS.ExecuteMemoryTable(sql, "SELECT kdobat, nmobat, satuan,harga,nmkategori,foto FROM tb_obat", Null,0)
  
    spasi = (120%x - (kolom * lebar_tombol))/(kolom + 1) 'spasi horizontal antara tombol a N kolom'spasi tombol

    intTotalTombol = listtombol.Size 'guarda el nomer total de tombol a list

    'Determina el alto del Panel del SV según el número, tamaño, columnas y separación de los botones
    SV.Panel.Height=(Ceil(intTotalTombol/kolom) * (tinggi_tombol + spasi)) + spasi + spasi+100dip ' tinggi spasi panel

    Dim datatombol () As String

    For Nomer = 0 To intTotalTombol - 1
        Dim tombol As Button
        Dim nama As Label
        Dim satuan As Label
        Dim harga As Label
        Dim kurang As Label
        Dim tambah As Label
        Dim lapis As  Label
        Dim jml As Label
        'Dim demo As ShoppingView
'        Dim ShoppingView1 = Sender
      
        datatombol = listtombol.Get(Nomer) 'Recupera de la Lista de Botones los datos de cada uno'Ambil dari Daftar Buttons data masing-masing
        'Pasa como parámetros el SV, un botón, nº del botón, texto e imagen del botón
        gambartombol (SV, tombol, Nomer,nama,satuan,harga,kurang,lapis, datatombol(0), datatombol(1),datatombol(2),datatombol(3),datatombol(5))
    Next
'    Dim index As Int
    'SV.Panel.GetView(Sender)
    'Dim pnl As Panel=
    'DoEvents
    'demo.Initialize("demo",Colors.Green,10,Colors.Yellow,Colors.Black)


  
End Sub


Sub gambartombol (SV As ScrollView, boton As Button,Nomer As Int,nama As Label,satuan As Label,harga As Label,kurang As Label,lapis As Label,id As Int, texto As String,sat As String,hrg As String, imagen As String)
    Dim x, y As Int
    Dim nama1 As String
  
    boton.Initialize("btnV")
    nama.Initialize("nama")
    satuan.Initialize("satuan")
    harga.Initialize("harga")
    kurang.Initialize("kurang")
    tambah.Initialize("tambah")
    lapis.Initialize("lapis")
    jml.Initialize("jml")
    'demo.Initialize("demo",Colors.Red,11,Colors.Black,Colors.Black)
  

    boton.Tag = Nomer 'se almacena el número de orden de cada botón
    'demo.Tag=Nomer

    Dim DestRect As Rect
    Dim icono As Bitmap ' mediante canvas inserto la imagen para despues redondear
    Dim iconoCanvas As Canvas
    'Dim harga As Label

    x = spasi + (lebar_tombol + spasi) * (Nomer Mod kolom) - 35dip'calcula la coordenada X del botón' ukuran samping scrollvies
    y = spasi + (tinggi_tombol + spasi) * Floor(Nomer/kolom) - 20dip 'calcula la coordenada Y del botón ukuran spaci tinggi scrollview

    SV.Panel.AddView(boton, x, y, lebar_tombol, tinggi_tombol) 'añade el botón al SV
    SV.Panel.AddView(nama,x-5dip, y+64dip, lebar_tombol+10dip, tinggi_tombol-130dip) 'añade el botón al SV
    SV.Panel.AddView(satuan,x+50dip, y+86dip, lebar_tombol-25dip, tinggi_tombol-130dip) 'añade el botón al SV
    SV.Panel.AddView(harga,x-5dip, y+86dip, lebar_tombol-20dip, tinggi_tombol-130dip) 'añade el botón al SV
    'SV.Panel.AddView(demo,x-5dip, y+164dip, lebar_tombol+10dip, tinggi_tombol-130dip))
    SV.Panel.AddView(kurang,x+15dip,y+98dip,5%x,tinggi_tombol-130dip)
    SV.Panel.AddView(jml,x+30dip,y+98dip,5%x,tinggi_tombol-130dip)
    SV.Panel.AddView(tambah,x+50dip,y+98dip,5%x,tinggi_tombol-200dip)
    icono.InitializeMutable(lebar_tombol, tinggi_tombol) ' inicializo el icono como bitmat modificable por el canvas
    'DestRect.Initialize(0dip, 0dip, ancho_boton, alto_boton - 50dip)
    DestRect.Initialize(0dip, 0dip, lebar_tombol, tinggi_tombol - 10dip)' atur spaci tulisan tombol
    iconoCanvas.Initialize2(icono)

    'Dibuja la imagen de fondo del botón, previamente redondeada (IE.Roundcorner)
    iconoCanvas.DrawBitmap(IE.RoundCorner(LoadBitmapSample(File.DirAssets, imagen,lebar_tombol, tinggi_tombol),40), Null, DestRect)' lengkungan tombol
  
    boton.SetBackgroundImage(icono) 'coloca en el fondo del botón

    boton.Text = texto
    boton.TextColor=Colors.Transparent
    nama.Text= texto
    nama.TextSize=9
    nama.TextColor=Colors.Black
    nama.Color=Colors.Gray
    nama.Gravity = Gravity.CENTER_HORIZONTAL
    nama1=nama.Text


    satuan.Text=sat
    satuan.TextSize=9
    satuan.TextColor=Colors.Black
    satuan.Color=Colors.Green
    satuan.Gravity = Gravity.LEFT

    harga.Text=hrg
    harga.TextSize=9
    harga.TextColor=Colors.Black
    harga.Color=Colors.Yellow
    harga.Gravity = Gravity.RIGHT
    kurang.Gravity= Gravity.CENTER_HORIZONTAL
    kurang.Text="-"
    kurang.TextSize=17
    kurang.Color=Colors.Red
    kurang.Tag=texto
    tambah.Text="+"
    tambah.TextSize=17
    tambah.Color=Colors.Green
    tambah.Gravity= Gravity.CENTER_HORIZONTAL
    tambah.SingleLine=True
    tambah.Tag=texto
  
    jml.Text="0"
    jml.TextSize=17
    jml.Color=Colors.Blue
    jml.Gravity= Gravity.CENTER_HORIZONTAL
  


End Sub

Sub btnv_click
    Dim tombol_tekan As Button
    Dim nama1 As String
    tombol_tekan = Sender
    ToastMessageShow("menekan tombol nº: " & tombol_tekan.tag & " - " & tombol_tekan.Text, False)

    Log(tombol_tekan.Text)
  
  
End Sub

Sub preparaDB 'Borra y copia de nuev la BD
    File.Delete(DBUTILS.GetDBFolder, "botones1.db")
    Dim rutaDB As String
    rutaDB=DBUTILS.CopyDBFromAssets("botones1.db")
    sql.Initialize (rutaDB, "botones1.db", True)
End Sub


Sub tambah_click
    Dim b As Label
    b = Sender
    Log(b)


End Sub
Sub jml_click


  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Label1_Click
  
End Sub
 
Last edited:

harry2017

Member
Licensed User
I cannot upload the project because its too large for forum
 

Attachments

  • 24-11-2017 02.10.jpg
    24-11-2017 02.10.jpg
    74.6 KB · Views: 339
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I changed the TAG of tambal and the other to be a ref to the target label. And the taget label hold the texto.

B4X:
Sub kurang_click
    Dim b As Label
    b = Sender
    Log(b)
    Log(b.Tag)
    Dim target As Label = b.Tag
    Log(target)
    target.Text = target.Text +1
End Sub
Sub tambah_click
    Dim b As Label
    b = Sender
    Log(b)
    Log(b.Tag)
    Dim target As Label = b.Tag
    Log(target)
    target.Text = target.Text -1


End Sub

ETA: It would be easier if you place your objects all in a Layout and load this layout. Your code would be much shorter and cleaner. Even simpler.
 

Attachments

  • tambal.zip
    13.4 KB · Views: 356
Last edited:
Upvote 0

harry2017

Member
Licensed User
emazing ...thanks for the answer DonManfred ....I want to user customlistview but ...after I search forum I cannot look example of 2 buton on one row ..
Don Manfred ...I dont know how make layout of 2 button in one row like that ..could you tell me please ...(Im newbie)

regard

harry
 
Upvote 0
Top