Autore Topic: [Lista contatti] Non filtra  (Letto 622 volte)

Offline max246

  • Utente junior
  • **
  • Post: 73
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    G1
  • Play Store ID:
    Christian
[Lista contatti] Non filtra
« il: 31 Ottobre 2010, 11:53:39 CET »
0
Ho preso uan classe che dovrebbe filtrarmi i contatti ( come quando scrivi un sms ), ma mi continua a visulaizzare tutti i contatti.

Codice (Java): [Seleziona]
public class ContactListAdapter extends CursorAdapter implements Filterable {

    public ContactListAdapter(Context context, Cursor c) {
        super(context, c);

        mContent = context.getContentResolver();
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final TextView view = (TextView) inflater.inflate(
                android.R.layout.simple_dropdown_item_1line, parent, false);
        Log.i("Cursor Count", "" + cursor.getCount());
        view.setText(cursor.getString(2) + " " + cursor.getString(0));
        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ((TextView) view).setText(cursor.getString(2) + " " + cursor.getString(0));
    }

    @Override
    public String convertToString(Cursor cursor) {
       return (cursor.getString(0));
    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (getFilterQueryProvider() != null) {
            return getFilterQueryProvider().runQuery(constraint);
        }
        StringBuilder buffer = null;
        String[] args = null;
        if (constraint != null) {
            buffer = new StringBuilder();
            buffer.append("UPPER(");
            buffer.append(Contacts.People.Phones.DISPLAY_NAME);
            buffer.append(") GLOB ?");
            args = new String[]{constraint.toString().toUpperCase() + "*"};
        }

        String[] phonesProjection = new String[]{Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE, Contacts.People.Phones.DISPLAY_NAME,
            Contacts.People.Phones._ID, Contacts.People.Phones.LABEL};
        Cursor phonesCursor = mContent.query(Contacts.Phones.CONTENT_URI, phonesProjection, null, null, Contacts.People.Phones.DEFAULT_SORT_ORDER);
        int phonesCursorCount = phonesCursor.getCount();
        System.out.println("phonesCursorCount=" + phonesCursorCount);
        return phonesCursor;
    }
    private ContentResolver mContent;
}

Codice (Java): [Seleziona]
 final AutoCompleteTextView txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);
       
        String[] phonesProjection = new String[] {Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE,Contacts.People.Phones.DISPLAY_NAME, Contacts.People.Phones._ID,Contacts.People.Phones.LABEL };
       ContentResolver cr = getContentResolver();
        Cursor phonesCursor = cr.query(Contacts.Phones.CONTENT_URI, phonesProjection, txtPhoneNo.getText().toString(), null, null); ContactListAdapter adapter = new ContactListAdapter(this, phonesCursor);
        txtPhoneNo.setAdapter(adapter);