Skip to content Skip to sidebar Skip to footer

How To Get String From Selected Item Of Simplecursoradapter?

I'm using an AutoCompleteTextView to suggest user some words from my sqlite db as they type the input string to search. I try to make the suggestion look friendly by using simple_l

Solution 1:

You need to use http://developer.android.com/reference/android/widget/CursorAdapter.html#getItem(int).

Cursorcursor= (Cursor) simple.getItem(position);
// retrieve the data from the cursor

Solution 2:

This seems to be a problem with SimpleCursorAdapter on 2.1, on 2.2 the cursor is positioned on the requested item and you can retrieve the column data but in 2.1 the cursor position is 0 and cursor.move(itemIndex) and cursor.moveToFirst() both return false.

I plan to do a RYO database adapter.

Solution 3:

Getting string from SimpleCurstor Adapter using cursor

@OverridepublicbooleanonSuggestionClick(int position) {
    //First get cursor from your Adapter,Cursorcursor= (Cursor) mAdapter.getItem(position);
    /* Then get string data from cursor's column, I am getting it from column 0 in this case. You can use your own column index. */
    String s=cursor.getString(0);
    //Then set the searchview or autotextview with that string
    mSearchView.setQuery(s, true); //true will submit the query 
}

Post a Comment for "How To Get String From Selected Item Of Simplecursoradapter?"