D
D
dimonstrer2018-04-02 01:48:03
Android
dimonstrer, 2018-04-02 01:48:03

Android: How to implement CursorAdapter with AutoCompleteTextView?

Hello.
The question is similar on Android: AutoCompleteTextView + SimpleCursorAdapter. Data filtering, is it possible? .
There is a DB. It is necessary to display elements from a DB in AutoCompleteTextView. I don't know how to properly create a CursorAdapter in order to use it for an AutoCompleteTextView. How to implement CursorAdapter?
MainActivity:

ListView userList;
    AutoCompleteTextView search;
    DatabaseHelper databaseHelper;
    SQLiteDatabase db;
    Cursor userCursor;
    SimpleCursorAdapter userAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        userList = (ListView)findViewById(R.id.list);
        search = (AutoCompleteTextView)findViewById(R.id.search);
        databaseHelper = new DatabaseHelper(getApplicationContext());
    }

    @Override
    public void onResume() {
        super.onResume();
        

        // открываем подключение/*
        db = databaseHelper.getReadableDatabase();

        userCursor =  db.rawQuery("select * from "+ DatabaseHelper.TABLE, null);

        String[] headers = new String[] {DatabaseHelper.name};
               userAdapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item,
                userCursor, headers, new int[]{android.R.id.text1, android.R.id.text2}, 0);
        search.setAdapter(userAdapter);*/
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        // Закрываем подключение и курсор
        db.close();
        userCursor.close();
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question