Android Question Spinner_ItemClick creates dropdown panels with different heights

Rob_HE

New Member
Hi guys and girls!

I am learning to program (B4A among others) for an industrial company and i need some help with an issue that i have to solve! We are trying to configure the WiFi settings of one of our devices using a bluetooth app and i have to finish the program my boss started to write! most of the tasks are doable but I have hit a bit of a bump with the implementation of the gui though! there's a list of spinners, textboxes etc that contain information about the devices current settings and you're supposed to be able to change them and send them back to the device (for example change the device's IP address). but some of the spinners require the creation of other items based on which option you choose. for example when i click on the spinner "Security" there are a few different options to choose from and based on which option you choose ("Keine", "WEP", "WPA"... etc) a different type of panel is supposed to open below that spinner (one of the three "PnlAuth1", PnlAuth2, PnlAuth3)... but what actually happens is that they open at the bottom of the screen, below all the other spinners etc! now my first idea was to switch their positions within the view which i couldn't find any commands for...

I also tried initializing them in the beginning with all the other items and setting their height (or width) to zero and then re-set their height/width to the proper value within the Spinner_ItemClick event, but as far as i understand theres two different types of height values for those panels. one height of the actual item and one height of the item's view when it gets created and i have only found a way to change the first through commands (which didn't solve my problem - just left a black box where the panel was before) but not the latter (which is the value i think i'd need to change?).


B4X:
 'lvSettings.Add(CreateCIPanel("PnlAuth1", lvSettings.AsView.Width, 40dip), 40dip, "Params")

in this line for example (if i'm correct) the "lvSettings.AsView.Width" is the item's width, the first "40dip" is the item's height and the second "40dip" is the view's height, right? so i found a way to change the first two which didn't really work because it left a black box where the item was before (because the "view" is still there, right? only the item inside is set to height zero?)

afaik the last "40dip" is the one that would need to be changed when a different option is chosen for my idea to work but i haven't found any commands to change this!



this is the beginning of the list of items:

B4X:
Sub Activity_Create(firsttime As Boolean)
   'Do not forget to load the layout file created with the visual designer.
   Activity.LoadLayout("DeviceSettings")

   pnlSSID = CreateCIEditText("Network identification", "SSID", lvSettings.AsView.Width, 70dip)
   lvSettings.Add(pnlSSID, 70dip, "SSID")                                         'INDEX 0
   
   pnlSecurity = CreateCISpinner("Security", Array As String("Keine", "WEP", "WPA", "WPA2", "802.1x EAP"), lvSettings.AsView.Width, 70dip)
   lvSettings.Add(pnlSecurity, 70dip, "Security")                                     'INDEX 1
   
   'lvSettings.Add(CreateCIPanel("PnlAuth1", lvSettings.AsView.Width, 40dip), 40dip, "Params")               'INDEX 2
   'lvSettings.Add(CreateCIPanel("PnlAuth3", lvSettings.AsView.Width, 270dip), 270dip, "Params")             'INDEX 3
   'lvSettings.Add(CreateCIPanel("PnlAuth2", lvSettings.AsView.Width, 70dip), 70dip, "Params")               'INDEX 4
   
   pnlDHCP = CreateCISpinner("Network Type", Array As String("DHCP", "Static"), lvSettings.AsView.Width, 70dip)
   lvSettings.Add(pnlDHCP, 70dip, "Network Type")                                     'INDEX 5

....



and this is the Spinner_ItemClick event

B4X:
Sub spSpinner_ItemClick (Position As Int, Value As Object)
   Dim index As Int = lvSettings.GetItemFromView(Sender)
   Dim pnl As Panel = lvSettings.GetPanel(index)
   Dim img As ImageView = pnl.GetView(0)
   Dim spn As Spinner = pnl.GetView(1)
   Dim lbl As Label = pnl.GetView(2)
   Dim i As Int
   Dim pnlTmp As Panel
   
   If index = 1 Then
     ' Security Spinner
     Log("spSecurity clicked: " & spn.SelectedIndex & "/" & spn.SelectedItem)
     'lvSettings.RemoveAt(2)
     If spn.SelectedIndex = 0 Then      'no security
       'pnlAuth1
     Else If spn.SelectedIndex = 4 Then    'EAP
       'pnlAuth3
     Else                  'simple password based security
       'pnlAuth2
     End If
   Else if index = 2 Then
     If spn.SelectedIndex = 1 Then
       'pnlIPSettings
     Else
       Return
     End If
   End If
   'Dim chk As CheckBox = lvSettings.GetView(2)
   lbl.Text = "Clicked!"
   'Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub

is my idea to resetting the height/width according to which panel is needed any good?

do you have any other idea how a function like this should be implemented?

or any URLs, YouTube vids or Documents where i can learn about this object based android gui and the commands i can use?
i already have "B4AUserGuide", "B4ABeginners GuideV3_2", "B4ACodeSnippets" and "B4A-Rapid-6-0" but i couldn't find anything in there

I wouldn't necessarily want a finished solution for this! it's better for learning stuff to do it by myself! some hints in the right direction would already be very much appreciated!

thanks for taking time to read this and help me! :)


Rob
 

Rob_HE

New Member
Ok so i've come a little farther it works nicely unless you click an item twice then the app crashes :D

it sais "The specified child already has a parent. You must call removeView() on the child's parent first"

but who's the parent?! i've been adding all these views to the ViewGroup "lvSettings" if I'm not mistaken but there's no removeView() command available for that ViewGroup...

my new code:
B4X:
Sub spSpinner_ItemClick (Position As Int, Value As Object)
   Dim index As Int = lvSettings.GetItemFromView(Sender)
   Dim pnl As Panel = lvSettings.GetPanel(index)
   Dim img As ImageView = pnl.GetView(0)
   Dim spn As Spinner = pnl.GetView(1)
   Dim lbl As Label = pnl.GetView(2)
   Dim i As Int
  

  ' Security Spinner
   If index = 1 Then

     lvSettings.RemoveAt(2)
     Log("spSecurity clicked: " & spn.SelectedIndex & "/" & spn.SelectedItem)

     If spn.SelectedIndex = 0 Then              ' no security
       lvSettings.InsertAt(2, pnlAuth1, 0dip, pnlAuth1)
     Else If spn.SelectedIndex = 4 Then            ' EAP
       lvSettings.InsertAt(2, pnlAuth3, 270dip, pnlAuth3)
     Else If spn.SelectedIndex = 1 Or 2 Or 3 Then      ' simple password based security
       lvSettings.InsertAt(2, pnlAuth2, 70dip, pnlAuth2)
     End If
  
  
   ' Network Type Spinner
   Else if index = 5 Then
    
     lvSettings.RemoveAt(4)
     Log("spDHCP clicked: " & spn.SelectedIndex & "/" & spn.SelectedItem)
        
     If spn.SelectedIndex = 1 Then
       lvSettings.InsertAt(4, pnlIPSettings, 160dip, pnlIPSettings)
     Else
       lvSettings.InsertAt(4, pnlIPSettings, 0dip, pnlIPSettings)
     End If
   End If
 
Last edited:
Upvote 0

Rob_HE

New Member
it works :) sorry for spamming the forum so quickly i'll try longer next time! it's hard to teach something to yourself!

B4X:
  If index = 1 Then
     
     lvSettings.RemoveAt(2)
     Log("spSecurity clicked: " & spn.SelectedIndex & "/" & spn.SelectedItem)

     If spn.SelectedIndex = 0 Then              ' no security
       pnlAuth1.RemoveView
       lvSettings.InsertAt(2, pnlAuth1, 0dip, pnlAuth1)
     Else If spn.SelectedIndex = 4 Then            ' EAP
       pnlAuth3.RemoveView
       lvSettings.InsertAt(2, pnlAuth3, 270dip, pnlAuth3)
     Else                            ' simple password based security
       pnlAuth2.RemoveView
       lvSettings.InsertAt(2, pnlAuth2, 70dip, pnlAuth2)
     End If
 
Upvote 0
Top