Android Question Text search -> display only 1 line

G-ShadoW

Active Member
Licensed User
Longtime User
Hello,

I have a file done.txt inside my application which I download from my ftp with httputils2
text file look's like this

1254278893454123:213123521252:32131231231:315353322352:12121212355
2315326674254621:545742021000:12314545545:231245544554:21587742345
etc...

So now I want to add edittext and when user correctly type 1254278893454123 ( only correct number )
the rest of numbers will be placed in edittext2.text="213123521252" , edittext3.text="32131231231" and
edittext4.text="315353322352"
edittext5.text="12121212355"

I use : as separator

So it will only read 1 line from txt file and populate rest of edittextboxes...

I dont know how to manage code for that :(
 

sorex

Expert
Licensed User
Longtime User
you need the split to seperate the lines on linefeeds to an array.

loop throught it, split the line again to get the 1st value and compare it.

if equal copy the other value to the textboxes.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
or

you can use indexof to search for that string and then use substr to get the rest if the values are always the same size.
if not use subtr from value to linefeed and then use regex.split.

options enough if you know what you're doing. :)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is a complete code (if you want the project I can post it) in line of what @NJDude and @sorex were advising you to do. The code reads the text file, then you click a button after you fill in the first box to automatically fill the other 4 boxes. However, I highly recommend you look at the SearchView class (or maybe AutoComplete EditText) where you can narrow down the list as you type, because your text box input is too long and you risk easily to type a wrong number :
B4X:
Sub Globals
    Dim MyList As List
    Dim Edittext1, Edittext2, Edittext3, Edittext4, Edittext5 As EditText
    Dim FilePath As String =File.DirRootExternal
    Dim FileName As String ="done.txt"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")  'has 5 boxes and 1 button
    If Not(File.Exists(FilePath,FileName)) Then
        File.Copy(File.DirAssets,FileName,FilePath,FileName)
    End If
    MyList.Initialize
    ReadTextFile
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ReadTextFile   'Read text file into a list
    Dim reader As TextReader       
    reader.Initialize(File.OpenInput(FilePath,FileName))
    Dim line As String
    line = reader.ReadLine
    Do While line <> Null 
      MyList.add(line)
     line = reader.ReadLine
    Loop               
    reader.Close  
End Sub
Sub Button1_Click  'populate text boxes
    For i=0 To MyList.Size-1
     Dim MyLine As String =MyList.Get(i)
     If MyLine.SubString2(0, MyLine.IndexOf(":")) =Edittext1.text Then
       Dim arrLine() As String = Regex.Split(":",MyLine)
        Edittext2.text= arrLine(1)
        Edittext3.text= arrLine(2)
        Edittext4.text= arrLine(3)
        Edittext5.text= arrLine(4)
        Exit
     End If
    Next
End Sub
 
Upvote 0
Top