开发者

fetching phone number according to name

i want to get number from name that i select from spinner how can i do.i think first i want to id for particular name.can any one help me.

public void onItemSelected(AdapterView parent, V开发者_如何学运维iew arg1, int pos, long arg3)

        {

            String name,phoneNumber;
            name=parent.getItemAtPosition(pos).toString();

            String[] projection1 = new String[]{
                    People._ID,People.NAME,People.NUMBER
                 };

            Cursor cur=getContentResolver().query(People.CONTENT_URI, projection1,People.NAME+"="+name , null, null);               

            phoneNumber=cur.getString(cur.getColumnIndex(People.NUMBER));
            Toast.makeText(parent.getContext(), "number="+phoneNumber,Toast.LENGTH_LONG).show();
           /* cur.moveToFirst();
                 if(cur.moveToFirst())
                 {
                     do
                     {



                     }while(cur.moveToNext());

                 }*/
        }


when you read the Contacts for the first time, save them to ArrayList , make your Custom Class to hold necessary information about each Contact like name and number, then put them into HashTable<String,CustomClass> , the key is the Contact number, then you can quickly get it from the HashTable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜