Listview Text File Question

sarim123

Member
Licensed User
Longtime User
How would i create a second text file for another activity. I tried renaming the text file but that didn't seem to work.
Here is the code
Tell me if you need the zip file.

B4X:
Sub Process_Globals
    Dim lstText As List
      Dim SelectedItem As Int      : SelectedItem = -1
End Sub

Sub Globals
   Dim edtText As EditText
   Dim ltvTexts As ListView
   Dim btnSubmit, btnDelete As Button
   Dim pnlmenu As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim i As Int
   
   Activity.LoadLayout("main2.bal")
   ltvTexts.ScrollingBackgroundColor = Colors.Transparent
   ltvTexts.Color = Colors.Transparent
   ltvTexts.Width = 100%x
   pnlmenu.Initialize ("")
   pnlmenu.Color = Colors.Transparent
   ltvTexts.ScrollingBackgroundColor = Colors.Transparent
   
    ltvTexts.SingleLineLayout.Label.TextColor = Colors.Black
   ltvTexts.SingleLineLayout.ItemHeight = 100dip
   ltvTexts.SingleLineLayout.Label.Height = 100dip

   'education-notepad-page.png.Width = 100%x   education-notepad-page.png.Height = 100%y
'   File.Delete(File.DirInternal, "Text.txt") ' just for testing
   If FirstTime = True Then
      If File.Exists(File.DirInternal, "Text.txt") = True Then
         lstText = File.ReadList(File.DirInternal, "Text.txt")
      Else
         lstText.Initialize
      End If
   End If
   FillListView
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   File.WriteList(File.DirInternal, "Text.txt", lstText)
End Sub

Sub btnSubmit_Click
   If edtText.Text <> "" Then
      lstText.InsertAt(0, edtText.Text)
      FillListView
      edtText.Text = ""
   Else
      Msgbox("No entry !", "ERROR")
   End If
End Sub

Sub FillListView
   ltvTexts.Clear
   For i = 0 To lstText.Size - 1
      ltvTexts.AddSingleLine(lstText.Get(i))
   Next
End Sub

Sub btnDelete_Click
   Dim Answ As Int

   If SelectedItem > -1 Then
      Answ = Msgbox2("Do you really want to delete " & lstText.Get(SelectedItem) & " ?", "Delete", "Yes", "", "No", Null)
      If Answ = DialogResponse.POSITIVE Then
         lstText.RemoveAt(SelectedItem)
         ltvTexts.RemoveAt(SelectedItem)
         SelectedItem = -1
         btnDelete.Visible = False
      End If
   Else
      Msgbox("No item selected !", "ERROR")
   End If
End Sub

Sub ltvTexts_ItemClick (Position As Int, Value As Object)
   SelectedItem = Position
   btnDelete.Visible = True
End Sub

'Sub ltvTexts
   'ltvTexts.TextSize = 20
   'ltvTexts.TextColor = Colors.Green
'End Sub

Sub Button1_Click
   Activity.LoadLayout("Main.bal")
End Sub
 

JonPM

Well-Known Member
Licensed User
Longtime User
Sorry what do you mean create a second text file for another activity? What exactly do you need to do? Sorry I don't understand the question.
 
Upvote 0

sarim123

Member
Licensed User
Longtime User
I have made a simple app where items from a listview are saved in a text file. that' is working but I want to make another text file for another part of the app.what would I do to make one more text file?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
but I want to make another text file for another part of the app.what would I do to make one more text file?
Sorry, I don't understand you need to be more precise.
With the same data ? If yes why a second file you read the current one in the other part.
If the data is different where do they come from ?

Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you want to make a copy of the same file into the same folder, use this:
B4X:
File.Copy(File.DirInternal,"Text.txt",File.DirInternal,"Textbackup.txt")
If you want to make a copy of the same file into a different folder and maintain the same name, you can use:
B4X:
File.Copy(File.DirInternal,"Text.txt",File.DirRootExternal,"Text.txt")
 
Upvote 0

sarim123

Member
Licensed User
Longtime User
No I am trying to make a duplicate code of this in a separate text file, sorry if I am being confusing


Sent from my iPad using Tapatalk HD
 
Upvote 0

sarim123

Member
Licensed User
Longtime User
Hi guys
all i am trying to do make a duplicate version of this code, but in a separate file
You know how im saving everything in a textfile, well i want to make another version of that by the textfile renamed to something different

Thanks Everybody!!!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I still don't understand.
What exactly do you want to do?
Have the same file duplicated ? If yes what for ?
Have other data saved in another file? If yes what data and where does it come from ?
If you expect concrete answers you must ask precise questions !
Explain what in detail you want to do.

Best regards.
 
Upvote 0

sarim123

Member
Licensed User
Longtime User
thanks margret!!!

(Have the same file duplicated ? If yes what for ?)Yes to put other data into the text not relative to the first text file.


Have other data saved in another file? If yes what data and where does it come from ? Yes the data comes from a listview.
Margret understands what im saying, im trying to make another textfile to put data from another listview into.
Sorry if im confusing
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Do you already have some code we could look at ?
What margret suggests you is a different file with exactly the same content.
If I understand it correctly you have a second ListView with different data and you want to save this data in a different file.
So do exactly the same as for the first ListView with different names.
For your information, in the previous example there are two views in parralel the ListView and a List and this List is saved not directly the ListView.
The easiest way to help you would be to post your code as a zip file.

Best regards.
 
Upvote 0

sarim123

Member
Licensed User
Longtime User
Thanks!

I finally figured it out. Big thanks to everyone!!!
Thanks for helping klaus
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…