1

我想在 中显示不同的短信发件人手机号码Autocomplete textview

当用户选择特定数字时。我需要显示该号码的许多消息。我知道如何从手机中获取联系人我在自动完成文本视图中显示它,但我需要短信发件人号码到自动完成文本。

这是我的代码:

public class contactapp extends Activity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.autocomplete_4);




    ContentResolver content = getContentResolver();
    Cursor cursor = content.query(Contacts.People.CONTENT_URI,
            PEOPLE_PROJECTION, null, null, Contacts.People.DEFAULT_SORT_ORDER);
    ContactListAdapter adapter = new ContactListAdapter(this, cursor);

    AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.edit);
    textView.setAdapter(adapter);
}


public static class ContactListAdapter extends CursorAdapter implements Filterable {
    Cursor cu;

    public ContactListAdapter(Context context, Cursor c) {
        super(context, c);
        mContent = context.getContentResolver();
        cu=c;
    }

    @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);
        view.setText(cursor.getString(5));
        return view;
    }

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

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

    @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.ContactMethods.NAME);

            buffer.append(") GLOB ?");
            args = new String[] { constraint.toString().toUpperCase() + "*" };
        }


        return mContent.query(Contacts.People.CONTENT_URI, PEOPLE_PROJECTION,
                buffer == null ? null : buffer.toString(), args,
                Contacts.People.DEFAULT_SORT_ORDER);

    }

    private ContentResolver mContent;        
}

private static final String[] PEOPLE_PROJECTION = new String[] {
    Contacts.People._ID,
    Contacts.People.PRIMARY_PHONE_ID,
    Contacts.People.TYPE,
    Contacts.People.NUMBER,
    Contacts.People.LABEL,
    Contacts.People.NAME,
};

}

4

0 回答 0