Android Question Using Searchview to capture String

Eric McDonald

Member
Licensed User
Hello all,

Fairly new to B4A, so this may be a simple question... but it's got me stumped.

I am using a SearchView as found in the SearchViewExample (found on the forum).

However, I am having difficulty implementing it into my own code. What I wish to do is take the selected text (from the csv file which is selected in the SearchView) and capture it into a String variable (it's an object right now... I think). From there, I'll be able to use that String variable in various instances, like a label, table, etc.

The zipped file of code is a slightly modified version of the example I'm getting this from. It basically adds a label, button, and String that I plan to further use in other code projects. Thought it would be simplest showing it this way.

Any help would be awesome guys, thanks for your time!
 

Attachments

klaus

Expert
Licensed User
You need to give more detailed information on what exactly you want to do with the selected value?
You can memorize the value in a process global string value and use it where ever you want.
What exactly do you mean with:
It basically adds a label, button, and String that I plan to further use in other code projects?
I'm afraid that you don't really know how Android does work.
I suggest you to watch Erels' videos, more specific B4A - Life Cycle and/or
to have a look at the B4X Booklets, more specific B4x Basic Language chapter 3 Program flow / Process life cycle.
 

DonManfred

Expert
Licensed User
What I wish to do is take the selected text (from the csv file which is selected in the SearchView) and capture it into a String variable (it's an object right now... I think). From there, I'll be able to use that String variable in various instances, like a label, table, etc.
You get the selected String in the Event
B4X:
Sub SearchView1_ItemClick(Value As String)
    Msgbox("Chosen value: " & Value, "")
End Sub
It is up to you to use the given String and assign it to a variable or use it in other ways.
For example you can add the selected value to a listbox
B4X:
Sub SearchView1_ItemClick(Value As String)
    'Msgbox("Chosen value: " & Value, "")
    ListView1.AddSingleLine(Value)
End Sub
I suggest to get an read @klaus Booklets (see link in Klaus post). As you are a new member you´ll find a lot of useful resources in there.
You also can watch Erels Tutorial videos (See the LEARN Link at the Top).
 

Eric McDonald

Member
Licensed User
@DonManfred that worked perfectly! Thanks so much, exactly what I was looking for. Didn't know it was that simple haha.
I'll be sure to look at some of those videos and booklets @klaus mentioned.
Thanks for the help guys!
 
Top