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

    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 :(
     
  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

    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. :)
     
  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 :
    Code:
    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
     
Loading...
  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