Android Question Can Define 2 tag sender for button on customview?

alisan94

New Member
hi to all
i have project by sql server and customlist view?
please help me on this:
can define 2 tag to send for button click rom clv?
i have no problem with btn.tag.
but the text of edittext is big problem.
tnx all
1667764056063.png


Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("spin")



Dim rs As JdbcResultSet

rs = cntmod.sql1.ExecQuery("SELECT dbo.FCustomer.customerCode,dbo.FCustomer.customerName,dbo.FCustomer.etebar,dbo.Person.phoneNo1,dbo.Person.address FROM dbo.FCustomer INNER JOIN dbo.Person ON dbo.FCustomer.person_ID = dbo.Person.id; ")
Do While rs.NextRow
Dim p As B4XView = xui.CreatePanel("")

p.LoadLayout("itemlable")
p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width,200dip)
.
.
.
.
Label7.Text = (rs.GetString("phoneNo1"))
Button1.Tag = (rs.GetString("customerCode"))
EditText1.Tag = EditText1.Text
CustomListView1.Add(p,"")
Loop
rs.Close

End Sub
Private Sub Button1_Click
Dim btn As Label = Sender
Dim text As EditText = Sender

cntmod.sql1.ExecNonQuery(" UPDATE dbo.FCustomer SET etebar = '" & text.Tag &"' WHERE customerCode = '" & btn.Tag & "'")
'Msgbox("حذف سند با موفقیت انجام شد","حذف")
ToastMessageShow(text.Tag,False)
End Sub
 
Last edited:

Knoppi

Active Member
Licensed User
Longtime User
You can do something like this (not tested)

B4X:
Sub Class_Globals
    Type UpdateType( CustomerCode As String, EditText As String)
End Sub

Private Sub YourSub
    Dim rs As ResultSet = Database.SQL.ExecQuery("SELECT dbo.FCustomer.customerCode,dbo.FCustomer.customerName,dbo.FCustomer.etebar,dbo.Person.phoneNo1,dbo.Person.address FROM dbo.FCustomer INNER JOIN dbo.Person ON dbo.FCustomer.person_ID = dbo.Person.id; ")
    Do While rs.NextRow
        '...
        Button1.Tag = CreateUpdateType( rs.GetString("customerCode"), EditText1.Text)
        '...
    Loop
End Sub

Private Sub Button1_Click
    Dim btn As B4XView = Sender
    Dim Update As UpdateType = btn.Tag
    Dim cmd As String = " UPDATE dbo.FCustomer SET etebar = ? WHERE customerCode = ?"
    Database.SQL.ExecNonQuery2( cmd, Array As String( Update.EditText, Update.CustomerCode))  'parameterized query
End Sub

Public Sub CreateUpdateType (CustomerCode As String, EditText As String) As UpdateType
    Dim t1 As UpdateType
    t1.Initialize
    t1.CustomerCode = CustomerCode
    t1.EditText = EditText
    Return t1
End Sub

or this
B4X:
Private Sub YourSub
    Dim rs As ResultSet = Database.SQL.ExecQuery("SELECT dbo.FCustomer.customerCode,dbo.FCustomer.customerName,dbo.FCustomer.etebar,dbo.Person.phoneNo1,dbo.Person.address FROM dbo.FCustomer INNER JOIN dbo.Person ON dbo.FCustomer.person_ID = dbo.Person.id; ")
    Do While rs.NextRow
        '...
        ' the parameters must be saved in the correct order
        Button1.Tag = Array As String( EditText1.Text, rs.GetString("customerCode"))
        '...
    Loop
End Sub

Private Sub Button1_Click
    Dim btn As B4XView = Sender
    Dim Update As List = btn.Tag
    Dim cmd As String = " UPDATE dbo.FCustomer SET etebar = ? WHERE customerCode = ?"
    Database.SQL.ExecNonQuery2( cmd, Update)
End Sub
 
Upvote 0

alisan94

New Member
1. Don't waste your time with activities. Switch to B4XPages.
2. Learn how to create parameterized queries. It is very very simple.
3. There is a single Tag property but you can store anything you like in it including an array with two elements.
TNX Erel.
please more help on this or best source to learn more. i'm new on b4a.
 
Upvote 0

alisan94

New Member
You can do something like this (not tested)

B4X:
Sub Class_Globals
    Type UpdateType( CustomerCode As String, EditText As String)
End Sub

Private Sub YourSub
    Dim rs As ResultSet = Database.SQL.ExecQuery("SELECT dbo.FCustomer.customerCode,dbo.FCustomer.customerName,dbo.FCustomer.etebar,dbo.Person.phoneNo1,dbo.Person.address FROM dbo.FCustomer INNER JOIN dbo.Person ON dbo.FCustomer.person_ID = dbo.Person.id; ")
    Do While rs.NextRow
        '...
        Button1.Tag = CreateUpdateType( rs.GetString("customerCode"), EditText1.Text)
        '...
    Loop
End Sub

Private Sub Button1_Click
    Dim btn As B4XView = Sender
    Dim Update As UpdateType = btn.Tag
    Dim cmd As String = " UPDATE dbo.FCustomer SET etebar = ? WHERE customerCode = ?"
    Database.SQL.ExecNonQuery2( cmd, Array As String( Update.EditText, Update.CustomerCode))  'parameterized query
End Sub

Public Sub CreateUpdateType (CustomerCode As String, EditText As String) As UpdateType
    Dim t1 As UpdateType
    t1.Initialize
    t1.CustomerCode = CustomerCode
    t1.EditText = EditText
    Return t1
End Sub

or this
B4X:
Private Sub YourSub
    Dim rs As ResultSet = Database.SQL.ExecQuery("SELECT dbo.FCustomer.customerCode,dbo.FCustomer.customerName,dbo.FCustomer.etebar,dbo.Person.phoneNo1,dbo.Person.address FROM dbo.FCustomer INNER JOIN dbo.Person ON dbo.FCustomer.person_ID = dbo.Person.id; ")
    Do While rs.NextRow
        '...
        ' the parameters must be saved in the correct order
        Button1.Tag = Array As String( EditText1.Text, rs.GetString("customerCode"))
        '...
    Loop
End Sub

Private Sub Button1_Click
    Dim btn As B4XView = Sender
    Dim Update As List = btn.Tag
    Dim cmd As String = " UPDATE dbo.FCustomer SET etebar = ? WHERE customerCode = ?"
    Database.SQL.ExecNonQuery2( cmd, Update)
End Sub
tnx man, i'm tested it but not work
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
too less information
which version did you try?
why does not it work?
what error message?

if you use the version with Type the declaration must be in
Sub Process_Globals 'Activity
or
Sub Class_Globals 'B4XPages
 
Upvote 0

alisan94

New Member
1. Don't waste your time with activities. Switch to B4XPages.
2. Learn how to create parameterized queries. It is very very simple.
3. There is a single Tag property but you can store anything you like in it including an array with two elements.
b4xpages method is complicated for me.
how can learn it simply?
 
Upvote 0
Top