AutoCompleteView Problem

  • Antworten:1
Bob Kelzo
  • Forum-Beiträge: 32

27.11.2012, 20:05:33 via Website

Hallo Leute,

Also ich hab mir in meiner App ein AutoCompleteTextView eingebaut, welches seine Elemente von einem Cursor erhält.

Folgendermaßen sieht mein Code aus:

1cursor = openHandler.autoCompleteQuery();
2startManagingCursor(cursor);
3completeAdapter = new AutoCompleteAdapter(this, cursor);
4AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.zweckfeld);
5text.setAdapter(completeAdapter);

Und so mein Adapter:

1public class AutoCompleteAdapter extends CursorAdapter {
2
3
4
5private LayoutInflater inflator;
6
7
8
9public AutoCompleteAdapter(Context context, Cursor c) {
10super(context, c);
11inflator = LayoutInflater.from(context);
12}
13
14
15
16public void bindView(View view, Context context, Cursor cursor) {
17TextView text1 = (TextView) view.findViewById(R.id.text1);
18text1.setText(cursor.getString(1));
19}
20
21
22public View newView (Context context, Cursor cursor, ViewGroup parent) {
23return inflator.inflate(R.layout.autocomplete_layout, null);
24}
25
26
27@Override
28public String convertToString(Cursor cursor) {
29int column = 1;
30return cursor.getString(column);
31}


Mein Problem ist nur, dass sobald man etwas eintippt, grundsätzlich alle Möglichkeiten vorgeschlagen werden, nicht nur die mit dem entsprechenden Buchstaben beginnenden.
Also ich meine tippt man "g" ein, wird z.B. auch "hallo" vorgeschlagen anstatt nur "guten Tag" oder "guten Morgen".


Ich hoffe ihr könnt mir da weiterhelfen.

Antworten
Bob Kelzo
  • Forum-Beiträge: 32

27.11.2012, 22:08:17 via Website

So, hab den Inhalt meines Cursors jetzt einfach mal mit einer for-Schleife folgendermaßen in eine ArrayList geschrieben und dann einfach nen ArrayAdapter benutzt.

1completeListe = new ArrayList<String>();
2cursor.moveToFirst();
3for (int i=0; i< cursor.getCount(); i++) {
4 completeListe.add(cursor.getString(1));
5 cursor.moveToNext();
6 }
7arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, completeListe);
8AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.zweckfeld);
9text.setAdapter(arrayAdapter);


Jetzt funktioniert die AutoCompleteTextView wenigstens schon mal wie gewollt. Würe mich allerdings trotzdem noch interessieren warum meine andere Methode nicht zum gewünschten Ergebnis führt.

Antworten