Issue about EditText_TextChanged and Length

Asmoro

Active Member
Licensed User
Longtime User
Hi all,

I'm learning about Length and don't understand
the errors I get when putting the lines underneath:

'If New = TestStr.substring2(0,New.Length) Then '

or

'If New = TestStr.substring2(0,New.Length -1) Then'

I get 'LastException java.lang.StringIndexOutOfBoundsException'
everytime I put to many characters in the searchbox.

I really appreciate your explaining..
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Ok, what is the meaning about -1 in this case then?
I am not sure what you mean.
If you are asking whether you should use (New.Length-1) rather than (New.Length), then you should use (New.Length-1) since indices go from 0...upto New.Length-1.
If you mean, found returns -1, then it means the text was not found in the list.
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Sorry, what I meant was I used the -1 as well and it did the job.

But as soon as I put too many characters in the searchbox, error
came out 'LastException java.lang.StringIndexOutOfBoundsException'.

Does it mean that I have to search the cause somewhere else in the prog?
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Thanks. I've made a quick implementation.
Now after putting some characters in the searchbox,
it didn't catch/retrieve the image.

So, what did I do wrong.(no log errors)


code:

B4X:
Sub acet_TextChanged (Old As String, New As String)
   acet.SingleLine = True
   
    If New <> "" Then    
        Dim TestStr As String
        found = -1
        For i = 0 To Main.Files.Size -1
            TestStr = Main.Files.Get(i)
         
   Dim nLength As Int
   nLength = New.Length
   If New.Length > TestStr.Length Then
      nLength = TestStr.Length
   End If

   If New  = TestStr.substring2(0,nLength-1)Then
       found = i
    Exit
    End If
       Next
        If found <> -1 Then ScrollView1.ScrollPosition = 350 + (found * 300)
    Else
        ScrollView1.ScrollPosition = 0
    End If
End Sub

note. forgot to mention, your code works:sign0098:..no issue with multiple characters anymore, just the catching character issue now.
 
Last edited:
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Hi all,

Thanks to thedesolatesoul I made a progress trying and learning about Length and AutoCompleteEditText...

But I'm not satisfied with the result.
After implementation of thedesolatesoul code, it didn't retrieve images using character search (filename) anymore.

On top of that, my searchbox "Focus" also behave very strange.
I expect that everytime touching the keyboard, it will raise up according to the code, well it didn't..:BangHead:

After a lot of testing and coding, no luck came to me.

So maybe someone could help me out with this testprog.

In the end, I would like to share this prog to anyone, using as a tutorial for their own purposes.
 
Last edited:
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Update: solved retrieving images by searching on specific characters.
One issue left about 'FocusChanged' to figure it out.
 
Upvote 0
Top