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


 
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
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…