Android Question Question about Lists

TheWind777

Active Member
Licensed User
Longtime User
I have always shied-away from lists. I knew they were powerful... but still don't understand them.

However, my current need forces me to finally understand them.

I have ten panels. On each of the panels I have an assortment of different EditText, Buttons, Labels, WebViews, etc.

I am now creating two functions... one to enable certain Activity Objects all-at-once and one to disable those same objects all-at-once with a for/next loop.

So, my thought was to use a list of lists... knowing that the advantage of using a list is that it can be any type of object.

However... here's my problem:

B4X:
[code]

sub globals
 ' Activity Objects not in Layout files:
 
 Dim WB_OBJECTS As List  : WB_OBJECTS.Initialize
 Dim WBTOC_OBJECTS As List  : WBTOC_OBJECTS.Initialize
 Dim ACIM_OBJECTS As List  : ACIM_OBJECTS.Initialize
 Dim ACIMTOC_OBJECTS As List  : ACIMTOC_OBJECTS.Initialize
 Dim RT_OBJECTS As List  : RT_OBJECTS.Initialize
 Dim SETTINGS_OBJECTS As List  : SETTINGS_OBJECTS.Initialize
 Dim HELP_OBJECTS As List  : HELP_OBJECTS.Initialize
 Dim LINKS_OBJECTS As List  : LINKS_OBJECTS.Initialize
 Dim ABOUT_OBJECTS As List  : ABOUT_OBJECTS.Initialize
 Dim QUEUE_OBJECTS As List  : QUEUE_OBJECTS.Initialize

 ' To make a List of Lists, later

 Dim PANELOBJECTS() As List 

end sub

Then, after all panels have been loaded, I populate each of the lists:

B4X:
sub Activity_Create

 WB_OBJECTS.Add(ButtonWBBack)
 WB_OBJECTS.Add(EditTextWBNumber)
 WB_OBJECTS.Add(ButtonWBForward)
 WB_OBJECTS.Add(ButtonWBQuestion)
 WB_OBJECTS.Add(ButtonWBMenu)
 WB_OBJECTS.Add(ButtonWBClose)
 WB_OBJECTS.Add(ButtonWBExercise)
 WB_OBJECTS.Add(ButtonWBTheme)
 WB_OBJECTS.Add(EditTextWBUR)
 WB_OBJECTS.Add(EditTextWBTitle)

 WBTOC_OBJECTS.Add(ButtonWBTOCQuestion)
 WBTOC_OBJECTS.Add(ButtonWBTOCMenu)
 WBTOC_OBJECTS.Add(ButtonWBTOCClose)
 WBTOC_OBJECTS.Add(ImageViewWBTOCUp)
 WBTOC_OBJECTS.Add(ImageViewWBTOCDown)
 WBTOC_OBJECTS.Add(WebViewWBTOC)
 WBTOC_OBJECTS.Add(ImageViewWBTOCTopGlow)
 WBTOC_OBJECTS.Add(ImageViewWBTOCBottomGlow)

 ' And so-on...

end sub

Next, I fill another list, so I can refer to them with a number 0 - 9 for each panel

B4X:
 PANELOBJECTS = Array As List(WB_OBJECTS,WBTOC_OBJECTS,ACIM_OBJECTS,ACIMTOC_OBJECTS,RT_OBJECTS, _
 SETTINGS_OBJECTS,HELP_OBJECTS,LINKS_OBJECTS,ABOUT_OBJECTS,QUEUE_OBJECTS)

Finally, I create two subs, hopefully to set the Enable on each of the List items to either True or False

B4X:
Sub EnableAllObjects(WhichPanel As Int)
 Dim z As Int
 Dim TheSize As Int
 Dim ThePanelList As List
 Dim TheObject As Object
 
 If DEBUG_Debugging3 Then Log(" +++ Begin EnableObjects()")
 
 ThePanelList = PANELOBJECTS(WhichPanel).Get(z)
 TheSize = ThePanelList.Size
 
 For z = 0 To TheSize - 1
 TheObject = ThePanelList.Get(z)
 TheObject.Enabled = True
 Next

 If DEBUG_Debugging3 Then Log(" --- End of EnableObjects()")
 If DEBUG_Debugging3 Then Log(" ")
End Sub


Sub DisableAllObjects(WhichPanel As Int)
 Dim z As Int
 Dim TheSize As Int
 Dim ThePanelList As List
 Dim TheObject As Object
 
 If DEBUG_Debugging3 Then Log(" +++ Begin EnableObjects()")
 
 ThePanelList = PANELOBJECTS(WhichPanel).Get(z)
 TheSize = ThePanelList.Size
 
 For z = 0 To TheSize - 1
 TheObject = ThePanelList.Get(z)
 TheObject
 Next

 If DEBUG_Debugging3 Then Log(" --- End of EnableObjects()")
 If DEBUG_Debugging3 Then Log(" ")
End Sub

As you can see... now I don't understand how to tell it to do the Enable on the different types of objects?

I was hoping that I could just define a generic 'object', point it to the list, and 'voila' it would know what kind of object it was because it was a List.

Nope.

I could possibly flag Checkbox as Tag 11, Buttons as Tag 12, EditText as Tag 13, etc. But don't know how to do that, either. Besides, I'm already using the tag value on some of those (particularly the Buttons) so they can all be sent to the same Sub name.

Help! I'm drowning.
 

LucaMs

Expert
Licensed User
Longtime User
You can not set Enabled or Disabled for an OBJECT (your TheObject)

You should use something like:

if TheObject is EditText then
private et as EditText
et = TheObjec
et.Enabled = True (or False)
else if TheObject is ...

etc
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…