Android Question Text search -> display only 1 line

Discussion in 'Android Questions' started by G-ShadoW, Jan 25, 2015.

  1. G-ShadoW

    G-ShadoW Active Member Licensed User


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


    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

    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 :(
  2. NJDude

    NJDude Expert Licensed User

    Search the forums for samples about REGEX.SPLIT.
  3. G-ShadoW

    G-ShadoW Active Member Licensed User

    It's only for split, I need search option and extract only one line
  4. sorex

    sorex Expert Licensed 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.
  5. sorex

    sorex Expert Licensed User


    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. :)
  6. Mahares

    Mahares Well Known Member Licensed 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 :
    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
    End If
    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       
    Dim line As String
        line = reader.ReadLine
    Do While line <> Null 
         line = reader.ReadLine
    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(
            Edittext3.text= arrLine(
            Edittext4.text= arrLine(
            Edittext5.text= arrLine(
    End If
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice