How to get string from selected item of SimpleCursorAdapter?

后端 未结 3 638
再見小時候
再見小時候 2020-12-06 06:34

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 b

相关标签:
3条回答
  • 2020-12-06 07:05

    Getting string from SimpleCurstor Adapter using cursor

        @Override
    public boolean onSuggestionClick(int position) {
        //First get cursor from your Adapter,
        Cursor cursor = (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 
    }
    
    0 讨论(0)
  • 2020-12-06 07:13

    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.

    0 讨论(0)
  • 2020-12-06 07:28

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

    Cursor cursor = (Cursor) simple.getItem(position);
    // retrieve the data from the cursor
    
    0 讨论(0)
提交回复
热议问题