saving list after exit problem

dev4you

Member
hi

i want to add list and after exit its save and after open its open the list
im using this code why its not work

B4X:
Dim ListView1 As ListView
Dim list1 As List

Sub Activity_Create
    ReadOptions
End Sub

Sub Activity_Pause (UserClosed As Boolean)
list1 = listview1
saveOptions
End Sub

Sub SaveOptions
    Dim TW As TextWriter
    TW.Initialize(File.OpenOutput(File.DirInternal, "file.txt", False))
    TW.WriteList(List1)
    TW.Close
End Sub

Sub ReadOptions
    If File.Exists(File.DirInternal, "file.txt") = False Then Return    
    Dim TW As TextReader
    TW.Initialize(File.OpenInput(File.DirInternal, "file.txt"))
    list1 = TW.ReadList
    TW.Close
End Sub
 

dev4you

Member
Erel

MY QUESTION IS HOW I CAN READ LIST FROM TXT FILE TO VIEWLIST

listview1 = Reader.ReadList THIS GIVES ERROR
listview1.AddSingleLine = Reader.Readline THIS GIVES ONE LINE

THANKS
 
Last edited:
Upvote 0

dev4you

Member
Thanks Erel im using the same code

B4X:
Dim list1 As List
Dim j As Int
If File.Exists(File.DirInternal, "1.txt") = False Then Return
list1 = File.Readlist(File.DirInternal, "1.txt")
j = list1.Size
If j < 0 Then Return
For i = 0 To j-1
listview1.AddSingleLine(list1.Get(i))
Next

but the problem in writing code to write the viewlist in list and save it to txt
 
Last edited:
Upvote 0

dev4you

Member
Erel Thanks,
i found this code and its work verrrrrrrrry well

B4X:
Dim list1 As List
Dim k As Int
list1.Initialize
k = listview1.Size
For i = 0 To k-1
list1.Add(listview1.GetItem(i))
Next
File.WriteList(File.DirInternal,"1.txt",list1)
 
Upvote 0
Top