I have a custom class view module that is comprised of a ListView that I create programatically, not with the designer.
This ListView is called ExplorerWindow.
When I access ExplorerWindow.Items.Size from WITHIN the class module I get an accurate count of items (my initial directory has 101 items in the ListView)
I have a subroutine that allows the Main module to access the index of the currently selected item in the ListView, Its through a class method so that they are not trying to access the ListView directly.
Any class view method that calls this sub gets the accurate ExplorerWindow.Items.Size (which is 101 items in my loaded directory)
HOWEVER ... when the Main module tries to access this public method, the ExplorerWindow.Items.Size comes back as 0. I select an item and then use the arrow keys to fire the SelecteItemChanged raised even in the Main module, and then try to use that Index with the public method and get item information.
I'm not trying to access the node directly from the Main module, I'm calling a public class method which should be Logging (for testing) the WindowExplorer.Items.Size.
Next try was to use a second sub to privately get the value of WindowExplorer.Items.Size and return it to the public method,to return it to the Main module:
Still no juice. When I call IndexURI from the Main module, both "size index:" and "remote index size:" report 0 items. When I call them from a method in the class module that is using the value and not returning it, then the count is not zero, its accurate.
I tried changing:
to
Still no juice.
Next test, try and directly access an item in the ListView that I know exists, because I'm looking at it in the ListView when I click on it.
Program exits saying:
What do I have to do to have the ListView Items Size return a value OR the listview items have contents, when something outside of the class module is trying to get that size through a class view module public method?
Every method that access the listview items size from within the class module gets data. I even raise events from the class view module To the Main module, and they work no problem. It's just when the request comes from outside of the class view module.
The part that makes it doubly confusing, is I have other public methods that are accessing Map data from the class view module, and those method are returning the data without any issues.
Is there something obscure I'm missing here, is it a matter of class view modules behaving differently than code class modules, or is this simply how it works and I have to adjust my approach?
This ListView is called ExplorerWindow.
When I access ExplorerWindow.Items.Size from WITHIN the class module I get an accurate count of items (my initial directory has 101 items in the ListView)
I have a subroutine that allows the Main module to access the index of the currently selected item in the ListView, Its through a class method so that they are not trying to access the ListView directly.
B4X:
Public Sub IndexURI(Index As Int) As String
Log("index: " & Index)
Log("size index: " & ExplorerWindow.Items.Size)
If Index > -1 And Index <= ExplorerWindow.Items.Size - 1 Then
Dim ap As AnchorPane = ExplorerWindow.Items.Get(Index)
Dim thisLabel As Label = ap.GetNode(1)
Return File.Combine(strCurrentDirectoryURI, thisLabel.Text)
End If
Return ""
End Sub
Any class view method that calls this sub gets the accurate ExplorerWindow.Items.Size (which is 101 items in my loaded directory)
HOWEVER ... when the Main module tries to access this public method, the ExplorerWindow.Items.Size comes back as 0. I select an item and then use the arrow keys to fire the SelecteItemChanged raised even in the Main module, and then try to use that Index with the public method and get item information.
I'm not trying to access the node directly from the Main module, I'm calling a public class method which should be Logging (for testing) the WindowExplorer.Items.Size.
Next try was to use a second sub to privately get the value of WindowExplorer.Items.Size and return it to the public method,to return it to the Main module:
B4X:
Public Sub IndexURI(index As Int) As String
Log("index: " & index)
Log("size index: " & ExplorerWindow.Items.Size)
Log("remote index size: " & winexp_items_size)
If index > -1 And index <= ExplorerWindow.Items.Size - 1 Then
Dim ap As AnchorPane = ExplorerWindow.Items.Get(index)
Dim thisLabel As Label = ap.GetNode(1)
Return File.Combine(strCurrentDirectoryURI, thisLabel.Text)
End If
Return ""
End Sub
Private Sub winexp_items_size As Int
Return ExplorerWindow.Items.Size
End Sub
Still no juice. When I call IndexURI from the Main module, both "size index:" and "remote index size:" report 0 items. When I call them from a method in the class module that is using the value and not returning it, then the count is not zero, its accurate.
I tried changing:
B4X:
Private ExplorerWindow As ListView
to
B4X:
Public ExplorerWindow As ListView
Still no juice.
Next test, try and directly access an item in the ListView that I know exists, because I'm looking at it in the ListView when I click on it.
B4X:
Public Sub IndexURI(index As Int) As String
Log("index: " & index)
Log("size indexUri: " & ExplorerWindow.Items.Size)
Log("remote index size: " & winexp_items_size)
Log("known item.get(1) is B4J: " & ExplorerWindow.Items.Get(1))
If index > -1 And index <= ExplorerWindow.Items.Size - 1 Then
Dim ap As AnchorPane = ExplorerWindow.Items.Get(index)
Dim thisLabel As Label = ap.GetNode(1)
Return File.Combine(strCurrentDirectoryURI, thisLabel.Text)
End If
Return ""
End Sub
Program exits saying:
B4X:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
What do I have to do to have the ListView Items Size return a value OR the listview items have contents, when something outside of the class module is trying to get that size through a class view module public method?
Every method that access the listview items size from within the class module gets data. I even raise events from the class view module To the Main module, and they work no problem. It's just when the request comes from outside of the class view module.
The part that makes it doubly confusing, is I have other public methods that are accessing Map data from the class view module, and those method are returning the data without any issues.
Is there something obscure I'm missing here, is it a matter of class view modules behaving differently than code class modules, or is this simply how it works and I have to adjust my approach?