German LinkedList mit Struktur ?

Micha122

New Member
Licensed User
Hallo,
meine erste post hier weil ich definitiv nicht weiterkomme.

Ich möchte einer LinkedList (CollectionsExtra) eine Struktur zuweisen.

Beispielsweise solch eine:
B4X:
Type KontaktStruct (Name As String,Strasse As String, Wohnort As String)

Ein kleines Beispiel wäre da echt klasse.

Grüße, Michael
 

DonManfred

Expert
Licensed User
Longtime User
Willkommen im Forum
 

Attachments

  • linkedlisttype.zip
    8.6 KB · Views: 264

Micha122

New Member
Licensed User
Hallo DonManfred,
danke für den Beispielcode.
Nachdem ich den Code angeschaut hatte war direkt alles klar.:)

Hier das ganze etwas abgespeckter für Anfänger:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim LL As LinkedList
    Type KontaktStruct (Name As String,Strasse As String, Wohnort As String)
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim k1, n1, n2 As KontaktStruct
    Dim k2 As KontaktStruct
    Dim k3 As KontaktStruct
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    k1.Initialize
    k1.Name = "Hans"
    k1.Strasse = "Hansstr."
    k1.Wohnort = "Hannove"
    
    k2.Initialize
    k2.Name = "Klaus"
    k2.Strasse = "Aachenerstr."
    k2.Wohnort = "Düren"

    k3.Initialize
    k3.Name = "Klaus2"
    k3.Strasse = "Aachenerstr. 2"
    k3.Wohnort = "Düren 2"
    
    LL.Initialize
    LL.Add(k1)
    LL.Add(k2)
    LL.Add(k3)
    
    
    Log ("First = " & CRLF & LL.First & CRLF & " : Last = " & LL.Last & CRLF)
    
    Log (ShowLL("All"))
    
    n1 = LL.RemoveFirst
    Log ("Removed first: " & CRLF & n1)
    n2 = LL.RemoveLast
    Log ("Removed last: " & CRLF & n2)
    
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub ShowLL(title As String)
    Dim msg As String
    For i = 0 To LL.Size - 1
        msg = msg & LL.Get(i) & CRLF
    Next
    Log (title & msg)
End Sub

Hoffe man kann den so lassen?
Habe noch nicht viel Erfahrung mit B4X.

Grüße und Danke!
 
Top