Android Question ListView and ToggleButton from database

Discussion in 'Android Questions' started by lamsri799, May 11, 2015.

  1. lamsri799

    lamsri799 Member Licensed User

    i am select data from database
    if status = 1 togglebutton = on
    else status =2 togglebutton = off
    but load avtivity
    all togglebutton is similar
    how to load avtivity so all togglebuttons is on or off as status

    Sorry for language i am beginner

    My code
    Code:
    Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
       
        
    Dim p As Panel
        p.Initialize(
    "")
        p.Color = 
    Colors.Black
        
    Dim b As Button
        b.Initialize(
    "button"'all buttons click events will be handled with Sub Button_Click
        Dim chk As ToggleButton
        chk.Initialize(
    "chk")
    If dbsql.IsInitialized = False Then dbsql.Initialize(File.DirInternal,"money.db",True)
        mccursor = dbsql.ExecQuery(
    "Select status FROM control  WHERE user_id = '"& id_login &"'order by control_id ")
            
    If mccursor.RowCount > 0 Then
                
    For i = 0 To mccursor.RowCount -1
                mccursor.Position =i
                
    Dim status As Int
                status = mccursor.GetInt (
    "status")
            
    If status = 1 Then
                chk.Checked = 
    True
                chk.TextColor = 
    Colors.Green
                chk.TextOn = 
    "ON"
            
    Else If status = 2 Then
                chk.Checked = 
    False
                chk.TextColor = 
    Colors.Red
                chk.TextOff = 
    "OFF"
            
    End If
            
    Next
            
    End If

        
    Dim lbl As Label
        lbl.Initialize(
    "")
        lbl.Gravity = 
    Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl.Text = Text
        lbl.TextSize = 
    16
        lbl.TextColor = 
    Colors.White
        b.Text = 
    "Delete"
        p.AddView(chk, 
    1%x2dip20%x, Height - 1dip'view #0
        p.AddView(lbl, 24%x2dip60%x, Height - 1dip'view #1
        p.AddView(b, 84%x2dip16%x, Height - 1dip'view #2
        Return p

    End Sub
     
  2. lamsri799

    lamsri799 Member Licensed User

    how to show each togglebutton as status ?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    What is the problem in the above code?
     
  4. lamsri799

    lamsri799 Member Licensed User

    Code:
    If dbsql.IsInitialized = False Then dbsql.Initialize(File.DirInternal,"money.db",True)
        mccursor = dbsql.ExecQuery(
    "Select status FROM control  WHERE user_id = '"& id_login &"'order by control_id ")
            
    If mccursor.RowCount > 0 Then
                
    For i = 0 To mccursor.RowCount -1
                mccursor.Position =i
                
    Dim status As Int
                status = mccursor.GetInt (
    "status")
            
    If status = 1 Then
                chk.Checked = 
    True
                chk.TextColor = 
    Colors.Green
                chk.TextOn = 
    "ON"
            
    Else If status = 2 Then
                chk.Checked = 
    False
                chk.TextColor = 
    Colors.Red
                chk.TextOff = 
    "OFF"
            
    End If
            
    Next
            
    End If
    all data select

    example
    data 1 status = 1
    data 2 status = 2
    data 3 status = 1

    result is

    all data togglebutton is ON
    i want to result data 1 togglebutton is ON
    data 2 togglebutton is OFF
    data 3 togglebutton is ON
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    I don't see any problem in this code. Use the debugger to make sure that the values coming from the database are as you expect. Why aren't you using ExecQuerySingleResult?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice