Android Question autocomplete not working on class instances

Exspecto

Member
Licensed User
Longtime User
I'm having a strange problem. For context, I'm in the middle of a Service module and create an instance of a class:

B4X:
Public Sub createItem
Dim oItem as Item
oItem.initialize
oItem.setID("123123123")
End Sub

And in the class it's something like:

B4X:
'Item class
Sub Class_Globals
  Private id As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
  id = CallSub(mainService, "generateUUID")
  appVersion = mainService.APP_VERSION
End Sub
Public Sub setID(sUUID As String) As Boolean
 
  If (CallSub2(mainService, "isUUID", sUUID)) Then
    id = sUUID   
    Return True
  Else
    Return False
  End If
 
End Sub

The problem is that when I type "oItem." and get the autocomplete popup window, it doesn't show the "setID" sub. Even if I start typing it like "oItem.set" and do ctrl+space, it doesn't appear. BUT, if I finish typing it all out and add the first paren, it brings up the parameter list.

I have several classes and they all seem to have this problem. Is this a bug, or is there something I need to add to the class to have it autocomplete correctly?
 

Exspecto

Member
Licensed User
Longtime User
Ah, I see the relevant part in your Classes tutorial now, but I've run into an additional issue.

The property autocomplete listing only works if your getters/setters don't boil down to the same name as the internal variable.

So here's an example class:

B4X:
'Test1 class
Sub Class_Globals

   Private id As String
   Private propX As Int
   Private y As Int

End Sub

Public Sub setX(t as Int)
  propX = t
End Sub

Public Sub setY(t as Int)
  y = t
End Sub

If I create an instance of this class, "x" will show up in autocomplete, but "y" will not. It seems if the part of the sub name minus the get/set boils down the the name of a private variable, it won't appear in the autocomplete.

B4X:
Dim oTest As Test1
oTest.initialize

oTest.x 'shows up with autocomplete since the internal variable isn't named "x"
oTest.y 'doesn't appear in autocomplete since the internal variable is named "y"

Now that I realize that's happening, I'll adjust my internal var naming habits, but this might be an easy "gotcha" for others.

Thanks again
 
Upvote 0

Exspecto

Member
Licensed User
Longtime User
I see that someone mentioned my other issue further down in the Classes tutorial here and you answered here

Would you consider adding that to the part where you talk about properties in the tutorial?

Thanks again
 
Upvote 0
Top