Android Question two lists and a searchview - IndexOf (Solved)

trepdas

Active Member
Licensed User
Longtime User
Hello good people
very noob questions. thank you for your help.

I need to do a simple task.

I have 2 lists.

list1 and list2.

I created two string arrays from the lists.
Question(6000) from list1
and
Answer(6000) from list2

(each list has 6000 items.)

searchview is populating list1.

with a searchview , user picks an item from list1
I need to fetch as a result the item that is located in list2 in the same position.

i.e

user picks Question(3420) and Answer(3420) will be displayed.

should be straight forward and easy.

my questions :
1.
what is the best way (fastest) to achieve this ?

I tried something pretty stupid to test it and it works but it takes a long time to achieve it :

B4X:
Sub Sview_ItemClick(Value As String)
    
    For tmpi=1 To 6000
        If Question(tmpi)=Value Then
           AnyString=Answer(tmpi)
            Exit
        End If
    Next
End Sub


can someone help with a smarter and faster solution?


question2 :
while searchview is building index , user has to wait a few secs.
is there a workaround for this ?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Use IndexOf to find the index of the String in the Questions.
Once you know the index you can use it to get the right Answer without a full loop.

something like

B4X:
Sub Sview_ItemClick(Value As String)
    Dim index As Int = questions.IndexOf(Value)
    Dim answer As String = answers.Get(index)
end
 
Upvote 0

trepdas

Active Member
Licensed User
Longtime User
fantastic.
idexof is what I needed...

and thank you for your quick reply.

as for the second question...
is there a way to let searchview build index in the background somehow without freezing the whole thing?
;)
 
Upvote 0

trepdas

Active Member
Licensed User
Longtime User
Thank you DonManfred.
you were faster than me...
:)

got the second answer too.
 
Upvote 0
Top