hi guys,

i have implemented a Custom CursorAdapter which will display all the
contacts with there images.

this is my code and it is working fine. now i want to have a Search
for this screen. i have tried a lot but couldn't find a way out.

so could some one please help me out ????

public class Contacts extends ListActivity {
        static final String[] cat = Constants.DEFAULT_CATEGORIES;
        static int[] id;
        static List<Long> contactId;
        DisplayContacts dispCont;
        List<String> number;
        Map<String, String> combination = new HashMap<String, String>();
        String isDisplayDetails;
        ProgressDialog dialog;

        private class DisplayContacts extends SimpleCursorAdapter implements
                        Filterable {
                private LayoutInflater mInflater;
                Context mCtx;

                public DisplayContacts(Context context, int layout, Cursor c,
                                String[] from, int[] to) {
                        super(context, layout, c, from, to);
                        // TODO Auto-generated constructor stub
                        mInflater = LayoutInflater.from(context);
                        this.mCtx = context;
                }


                @Override
                public void bindView(View view, Context context, Cursor c) {
                        // TODO Auto-generated method stub
                        // int idCol = c.getColumnIndex(Phones._ID);
                        // try {
                        int nameCol = c.getColumnIndex(Phones.NAME);
                        int numCol = c.getColumnIndex(Phones.NUMBER);
                        int foreign = c.getColumnIndex(Phones.PERSON_ID);
                        String name = c.getString(nameCol);
                        String number = c.getString(numCol);
                        // long id = c.getLong(idCol);
                        long phoneForeign = c.getLong(foreign);
                        // View v = mInflater.inflate(R.layout.contacts, 
parent, false);
                        TextView name_text = (TextView)
view.findViewById(R.id.contactName);
                        if (name_text != null) {
                                name_text.setText(name);
                        }

                        TextView num_text = (TextView) 
view.findViewById(R.id.number);
                        if (num_text != null) {
                                num_text.setText(number);
                        }

                        // set the profile picture
                        ImageView profile = (ImageView) 
view.findViewById(R.id.imgContact);
                        if (profile != null) {
                                // Uri uri = 
ContentUris.withAppendedId(People.CONTENT_URI,
                                // id);
                                Cursor cur = 
getContentResolver().query(Photos.CONTENT_URI,
                                                null, Photos.PERSON_ID + "='" + 
phoneForeign + "'",
                                                null, null);
                                byte[] b = null;
                                if (cur != null) {
                                        if (cur.moveToNext()) {
                                                int imgColumn = 
cur.getColumnIndex(Photos.DATA);
                                                b = cur.getBlob(imgColumn);
                                        }
                                }
                                Bitmap bm = null;
                                if (b != null) {
                                        ByteArrayInputStream bytes = new 
ByteArrayInputStream(b);
                                        BitmapDrawable bmd = new 
BitmapDrawable(bytes);
                                        bm = bmd.getBitmap();
                                        profile.setImageBitmap(bm);
                                } else {
                                        
profile.setImageResource(R.drawable.defaultcontact);
                                }
                                ImageView indicator = (ImageView) 
view.findViewById(R.id.is);
                                boolean assign = isAssign(number);
                                if (assign) {
                                        // set the profile picture
                                        
indicator.setImageResource(R.drawable.ok);
                                } else {
                                        
indicator.setImageResource(R.drawable.delete);
                                }
                        }
                        dialog.dismiss();
                        /*
                         * } finally { if (c != null) { c.close(); } }
                         */
                }

                @Override
                public Object getItem(int position) {
                        // TODO Auto-generated method stub
                        return super.getItem(position);
                }

                @Override
                public Cursor runQueryOnBackgroundThread(CharSequence 
constraint) {
                        // TODO Auto-generated method stub
                        if (getFilterQueryProvider() != null) {
                                return 
getFilterQueryProvider().runQuery(constraint);
                        }

                        StringBuilder buffer = null;
                        String[] args = null;
                        if (constraint != null) {
                                buffer = new StringBuilder();
                                buffer.append("UPPER(");
                                buffer.append(People.NAME);
                                buffer.append(") GLOB ?");
                                args = new String[] { 
constraint.toString().toUpperCase() + "*" };
                        }

                        return 
mCtx.getContentResolver().query(Phones.CONTENT_URI, null,
                                        buffer == null ? null : 
buffer.toString(), args,
                                        Phones.NAME + " ASC");
                }

        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
                setTitle("Color Eye D - Contacts");
                dialog = ProgressDialog.show(Contacts.this, "",
                                "Loading. Please wait...", true);

                Cursor cursor = getContentResolver().query(Phones.CONTENT_URI, 
null,
                                null, null, Phones.NAME + " ASC");
                startManagingCursor(cursor);

                String[] columns = new String[] { Phones.NAME, Phones.NUMBER };
                int[] names = new int[] { R.id.contactName, R.id.number };
                dispCont = new DisplayContacts(this, R.layout.contacts, cursor,
                                columns, names);
                setListAdapter(dispCont);
                // setListAdapter(new DisplayContacts(this));
                registerForContextMenu(getListView());
                // cursor.close();

        }

}

regards,
Mike

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to