Android Question How can I collect controls infomation inside panel?

dragonguy

Active Member
Licensed User
Longtime User
I created a panel and let user add controls inside the panel, then i want collect the infomation about the controls.

i did it in vb.net

B4X:
Dim mycontrol as Control
            If answer20 = 1 Then
                        For Each mycontrol In Me.panel_status.Controls
                            If (mycontrol.GetType.ToString = "Smart_Home___TCP.DoubleBufferedPictureBox") Then
                                If mycontrol.Name = "ID09" Then
                                    mycontrol.BackColor = Color.Green
                                End If
                            End If
                        Next
                    End If

how can i do it at android?
 

dragonguy

Active Member
Licensed User
Longtime User
Something like:

B4X:
Sub GetViews
   For Each V As View In PanelMain
      If V Is EditText Then
         Log("EditText")
      EndIf
      If V Is Button Then
         Log("Button")
      EndIf
      'etc
   Next
End Sub

i built another layout using CustomListView, i cant catch the button info.
my code is

B4X:
Sub ReadDataBase
    Dim Row As Int
    Dim Query As String
    Dim Cursor1 As Cursor
    Dim ButtonName As String
 
    Query = "SELECT ButtonName,ButtonCode FROM ButtonProfile where ConnectionName = ? and GroupName = ?"
    Cursor1 = Main.SQL1.ExecQuery2(Query, Array As String (MainMenuControl.MainMenuControlConnectionName,MainMenuControl.MainMenuControlGroupName))
    If Cursor1.RowCount > 0 Then                     
        RowNumber = Cursor1.RowCount                 
        For Row = 0 To RowNumber - 1
            Cursor1.Position = Row                     
            ButtonName = Cursor1.GetString("ButtonName")
            ButtonCode1 = Cursor1.GetString("ButtonCode")
            'clv3.AddTextItem(ButtonName,ButtonName)
            clv3.Add(CreateListItem(ButtonName, clv3.AsView.Width, 50dip), 50dip, ButtonName)
        Next
    End If
    Cursor1.Close                                     
End Sub

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.white
    Dim btn As Button
    btn.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextSize = 20
    lbl.TextColor = Colors.Black
    btn.Tag = ButtonCode1
    p.AddView(lbl, 5dip, 2dip, 150dip, Height - 4dip) 'view #0
    p.AddView(btn, 75%x, 2dip, 25%x, Height - 4dip) 'view #1
    Return p
End Sub

B4X:
For Each V As Button In clv3
    If V.Tag=prefix & "1" Then
        V.Color=Colors.DarkGray
         V.Text="OFF"
     End If

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private clv3 As CustomListView


End Sub

error code:
B4X:
Compiling generated Java code.          Error
B4A line: 786
For Each V As Button In clv3
javac 1.7.0_51
src\b4a\example\controlmenu.java:1140: error: incompatible types
final anywheresoftware.b4a.BA.IterableList group647 = mostCurrent._clv3;
                                                                ^
  required: IterableList
  found:    customlistview
1 error
 
Last edited:
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
B4X:
If answer0108 = 32 Then
      For i = 0 To clv3.GetSize - 1
          Dim pnl As Panel = clv3.GetPanel(i)
          Dim V As Button = pnl.GetView(1)
              If V.Tag=prefix & "6" Then
                 V.Color=Colors.DarkGray
                 V.Text="OFF"
                 V.TextColor=Colors.White
           End If
         Next   
End If

i try code like this but my app get fc!
got any solution for it?

InstantNote_20140307_202419.png
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
i try in release mode also same problem. my app got a 100 + button and behide the the layout have many calculation.
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
I know why my app keep hang, i make a stupid mistake in my code. i use many "for next" in my app, some part i use same variable name, so it make my app hang all the time. Now I'm fixed it already, thanks all for you. now happy coding :)
 
Upvote 0
Top