Android Question assign button.tag to object?

hi, i face problem to assign button.tag to object.
the problem is that if i assign button.tag to object it give me last assigned object.

if i clicke on any button it give my the last added OptionName text.

i want to if i click on the button geve me the result that i have asigned to button.tag

My Code is :
B4X:
Sub Process_Globals

    Dim SQL1 As SQL

    Dim Item_ID As Int = 1

    Type Option_OBJECT(Option_ID_Int As Int,Option_Name As String)

  

End Sub



Sub Globals

    Dim TabHost1 As TabHost

    Dim scv1 As ScrollView

End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Item_Details_Form")

    TabHost1.Initialize("TabHost1")

    If SQL1.IsInitialized =False Then

        SQL1.Initialize(Main.Sqlite_Folder,Main.Sqlite_File,False)

    End If 

Load_Options_Flocks()

End Sub



Sub Load_Options_Flocks()

    Try
  
        Dim Cursor As Cursor

        Cursor = SQL1.ExecQuery("SELECT * FROM Options_Flocks_Table WHERE Option_Item_ID=" & Item_ID)
        If Cursor.RowCount > 0 Then
            scv1.Initialize2(0,"scv1")
            scv1.Panel.Height = 100dip * Cursor.RowCount + 1000
            scv1.Width = 100%x - 10%x
            Dim Option_Obj As Option_OBJECT
            For i = 0 To Cursor.RowCount - 1

                Cursor.Position = i

                Dim Option_ID As Int = Cursor.GetInt("Option_ID")
                Dim Option_Name As String = Cursor.GetString("Option_Name")
                Option_Obj.Option_ID_Int=Option_ID
                Option_Obj.Option_Name=Option_Name
                Dim Btn1 As Button
                Btn1.Initialize("Button")
                Btn1.Height= 2dip
                Btn1.Width = TabHost1.Width - 10%x
                Btn1.TextColor = Colors.Blue
                Btn1.Text = Option_Name
                Btn1.Tag = Option_Obj
                scv1.Panel.AddView(Btn1,5dip,5dip + i * 100dip,scv1.Width - 10dip, 90dip)
            Next
            TabHost1.AddTab2("Flock",scv1)
        End If
    Catch
        ToastMessageShow(LastException,True)
        Log(LastException)
    End Try
  
End Sub

Sub Button_Click
    Dim btn As Button = Sender
    Dim myitem As Option_OBJECT
    myitem = btn.Tag
    ToastMessageShow(myitem.Option_Name,False) 'The Problem is Here It Give me The Last Option Name (All Buttons Give Me The Same Result)
  
End Sub

what is the error here ?
 

Attachments

  • 1.jpeg
    1.jpeg
    48.4 KB · Views: 20
Last edited:
Top