android - SearchView: Getting the selected item from the suggestion listener -


i have search view has suggestions populated matrixcursor (because have array of strings). item being selected user. far able position user has clicked on suggestion list:

searchview.setonsuggestionlistener(new searchview.onsuggestionlistener() {         @override         public boolean onsuggestionclick(int position) {             string selecteditem = (string)madapter.getitem(position);             log.e("search view", selecteditem);             return true;         } 

however have got error: android.database.matrixcursor cannot cast java.lang.string , not sure how go around it. appreciate kind of help.

the position brings suggested list selected item position. if suggested list cursor (from exception may think matrixcursor), have item in position of cursor.

public boolean onsuggestionclick(int position) {     cursor searchcursor = mysearchviewadapter.getcursor();     if(searchcursor.movetoposition(position)) {         string selecteditem = searchcursor.getstring(columnoftheitemstringinthematrix);     } } 

columnoftheitemstringinthematrix column number assigned when created matrix , added row. example:

matrixcursor c = new matrixcursor("item"}); 

and when added row (a new item matrixcursor):

string item =  "myitem"; c.addrow(new object[]{item}); 

then columnoftheitemstringinthematrix = 0;


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -