get phone number in android
<p>I got all contact name in spinner. How do I get phone number according to select name? Please help me.</p>

<pre><code>public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ArrayAdapter adapter;
        int x=0;
        Spinner spinner=(Spinner)findViewById(R.id.Spinner);

        String[] projection = new String[]{
                People.NAME,
                People.NUMBER,People._ID
             };
        ContentResolver cr=getContentResolver();

        Cursor cursor=cr.query(People.CONTENT_URI, projection,null, null,null);
        cursor.moveToFirst();
        if(cursor.moveToFirst())
        {
            String name[]=new String[cursor.getCount()];
            do
            {

                 name[x]=cursor.getString(cursor.getColumnIndex(People.NAME));
                //name=cur.getString(cur.getColumnIndex(People.NAME));
                 //phoneNumber=cur.getString(cur.getColumnIndex(People.NUMBER));
                 //id=cur.getString(cur.getColumnIndex(People._ID));
                x++;

                //Toast.makeText(this,"name:"+name+"number:"+phoneNumber,Toast.LENGTH_LONG).show();

            }while(cursor.moveToNext());
            adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item,name);
            spinner.setAdapter(adapter);
            spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
        }
        cursor.close();

    }
</code></pre>
