There is an application that uses a database in which there is a table with 2 fields. On the form there is an EditText and a button. When we enter a word in the text field and click OK, the query is executed and all entries corresponding to the entered word are displayed in TextView.
Actually the question is: Is it possible to make it so that when you start typing letters in EditText, you will see a list of suggested options, like when searching in Google?
Not working anyway. That's what happened
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Создаем объект типа DictionaryDBHeler db = new DictionaryDBHeler(this); //Вызываем методы создания и открытия БД try { db.createDataBase(); db.openDataBase(); } catch (IOException ex) { } spinner = (Spinner) findViewById(R.id.spinner); // Настраиваем адаптер ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.types, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Вызываем адаптер spinner.setAdapter(adapter); txtResult = (TextView) findViewById(R.id.txtResult); txtResult.setMovementMethod(new ScrollingMovementMethod()); txtSearch = (AutoCompleteTextView) findViewById(R.id.txtSearch); txtSearch.setThreshold(3);//Указываем сколько символов нужно ввести, чтобы появились варианты автозаполнения btnSearch = (ImageButton) findViewById(R.id.imageButton); scAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, new String[] {DictionaryEntry.COLUMN_WORD}, new int[] {android.R.id.text1}, 0); txtSearch.setAdapter(scAdapter); scAdapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence str) { return getCursor(str); } }); scAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { public CharSequence convertToString(Cursor cur) { int index = cur.getColumnIndex(DictionaryEntry.COLUMN_WORD); return cur.getString(index); }}); } public Cursor getCursor(CharSequence str) { String query = "SELECT " + DictionaryEntry.COLUMN_WORD + " FROM " + DictionaryEntry.TABLE_NAME + " WHERE " + DictionaryEntry.COLUMN_WORD + " = " + "\"" + str; Cursor cursor = db.database.rawQuery(query, null); return cursor; }