Android Question Set Data into Object

fishwolf

Well-Known Member
Licensed User
Longtime User
How to can set single data into a Object?

Example set all data into object
B4X:
Dim TableList As List

  TableList.Initialize
  TableList.Add(Array(Ind+1, ResultMap.Get("name") )

Flow for set single data into object
B4X:
Dim TableList As List
Dim TableRow as ????

  TableList.Initialize

  TableRow???? = Ind+1
  TableRow???   = ResultMap.Get("name")

  TableList.Add(TableRow)
 

fishwolf

Well-Known Member
Licensed User
Longtime User
B4X:
Dim row() As Object = TableRow.Get(5) 'update the sixth item
row(0) = 111
row(1) = "asdasd"
Set the all list with the last value

i'm tring to set the b4xTable from Map derived from a json

B4X:
Sub ShowResults (DataMap As Map)
Dim ResultMap As Map
Dim ResultsList As List
Dim TableRow(2) As Object
Dim Ind As Int
Dim TableList As List

  
    ResultsList = DataMap.Get("results")
    Log ("ResultsList=" & ResultsList)
 
    TableList.Initialize
          
    For Ind = 0 To ResultsList.Size - 1
        ResultMap = ResultsList.Get(Ind)
        
        TableRow(0) = Ind + 1
        TableRow(1) = ResultMap.Get("name")
      
        TableList.Add(TableRow)
  
    Next

    TableResults.SetData(TableList)
  
End Sub

TableList=(ArrayList) [[Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124, [Ljava.lang.Object;@1634124]
 
Last edited:
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
B4X:
    For Ind = 0 To ResultsList.Size - 1
        dim ResultMap as Map = ResultsList.Get(Ind)
        Dim TableRow(2) As Object
        TableRow(0) = Ind + 1
        TableRow(1) = ResultMap.Get("name")
     
        TableList.Add(TableRow)
 
    Next
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
Thank you.

i understand that the problem is that TableRow is add to list for reference, if you define olny once the variable, the reference is always the same.
If define the variable into the loop, the reference of variale is always different.

B4X:
' Wrong
Dim TableRow(2) As Object 
For Ind = 0 To ResultsList.Size - 1
        dim ResultMap as Map = ResultsList.Get(Ind)
        ' Correct
        Dim TableRow(2) As Object
        TableRow(0) = Ind + 1
        TableRow(1) = ResultMap.Get("name")
     
        TableList.Add(TableRow)
 
    Next
 
Upvote 0
Top