Domanda

Ho creato una visualizzazione personalizzata estendendo AutoCompleteTextView (con una funzione specializzata chiamata setCursorAdapter). Sto fornendo un SimpleCursorAdapter e l'aggiunta di un FilterQueryProvider. Sto usando questo per un elenco dei numeri di cui ho bisogno la possibilità di cercare in qualsiasi punto all'interno del numero per una partita.

public void setCursorAdapter(final Uri uri, final String key) {

        Cursor c = getContext().getContentResolver().query(uri,
                new String[] { "_id", key }, null, null, key);
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(),
                android.R.layout.simple_dropdown_item_1line, c,
                new String[] { key }, new int[] { android.R.id.text1 });

        this.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                ((SimpleCursorAdapter) getAdapter()).getFilterQueryProvider()
                        .runQuery(s);

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }
        });

        adapter.setFilterQueryProvider(new FilterQueryProvider() {

            @Override
            public Cursor runQuery(CharSequence constraint) {
                Cursor c = getContext().getContentResolver().query(uri,
                        new String[] { "_id", key },
                        key + " LIKE '%" + constraint + "%'", null, key);
                return c;
            }
        });
        setAdapter(adapter);
    }

Tutto sta funzionando perfettamente, fino a quando seleziono il valore dalla giù goccia. Il valore che ricevo nella finestra EditText: android.content.ContentResolver $ CursorWrapperInner @ ...

Come evitare questo ed ottenere la mia (numerico) il testo visualizzato correttamente.

Grazie

È stato utile?

Soluzione

Risolto: SimpleCursorAdapter.converToString (cursore) - I overrode questa funzione per estrarre il valore

.

Grazie

Altri suggerimenti

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top