Skip to content
Advertisement

Populate single TextView with multiple SQL columns using SimpleCursorAdapter (Suggestion for searchbox)

I’m using SQL as datasource. My app’s searchbox has autosuggestion, but currently it’s only able to return the results of 1 column (e.g. column1). I want it to be able to search in 2 columns (so, column1 + column2) and show both column’s result in the autosuggestion dropdown. This is the code I’m trying to implement the method with, but without any success.

JavaScript

and this is the SQL query behind it

JavaScript

I think the main problem is here:

JavaScript

because with this order, if I search something, it will return column1’s list, but if I change the order from {“column1”, “column2”} to {“column2”, “column1”}, the autosuggestion will show column2’s results only. I understand that I should do something with this line:

JavaScript

but I didn’t find any detailed info on this, only a solution where the columns would be shown in different rows, but I need both results to show in a single dropdown. Thank you for your time and for reading this!

Advertisement

Answer

Ok, after some days resting I just saw it clear, the way to accomplish this is changing this string:

JavaScript

To this:

JavaScript

This way, the search will happen in both rows, so the suggestions will be taken and shown from both rows.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement