Hi everyone,
I seem to be having a problem when I run my code. For some reason, it seems that when I click my save button to save the list to the file, when I load the app up again and it loads the data, it's loading blank items into the list which I don't really want. Would anyone be able to shed some light on this at all please?
Many thanks!
My save button code:
and my first-boot code:
Cheers
Ash
I seem to be having a problem when I run my code. For some reason, it seems that when I click my save button to save the list to the file, when I load the app up again and it loads the data, it's loading blank items into the list which I don't really want. Would anyone be able to shed some light on this at all please?
Many thanks!
My save button code:
B4X:
Sub saveBtn_Click
'add an item to the scroll list
noteList.AddSingleLine2("Note " & noteID, noteText.Text)
''Msgbox(noteText.Text,"")
noteFilelist.Add(noteText.text)
''Msgbox("file contains: " & noteFilelist,"")
''ToastMessageShow("list currently contains "¬eList.Size, False)
File.WriteList(File.DirRootExternal, "notes.txt", noteFilelist)
noteID = noteID+1
End Sub
and my first-boot code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layout")
noteList.Initialize("noteList")
noteFilelist.Initialize
noteID = 1
If File.Exists(File.DirRootExternal, "notes.txt") Then
noteFilelist = File.ReadList(File.DirRootExternal, "notes.txt")
'Msgbox("file found. loaded "&(noteFilelist.Size/2), "")
For i=0 To noteFilelist.Size-1
If noteFilelist.Get(i) <> "" Then
noteList.AddSingleLine2("Note " & noteID, noteFilelist.Get(i))
noteID = noteID + 1
Else
noteFilelist.RemoveAt(i)
End If
Next
''Dim i As Int
''i=1
''Do While i < noteFilelist.Size-1
'' noteList.AddSingleLine2(noteFilelist.get(i),noteFilelist.Get(i+1))
'' i=i+2
''Loop
Else
Msgbox("no file found, creating new file", "")
File.WriteList(File.DirRootExternal, "notes.txt",noteFilelist)
'File.WriteList(File.DirRootExternal, "notes.txt",noteFilelist)
''Activity.AddView(noteList,0,30,100%x,20%y)
End If
Activity.AddView(noteList,0,30,100%x,20%y)
End Sub
Cheers
Ash