Retrieving contacts in list view and displaying the name and phone number in next activity with click action
<p>I have got the code where through content provider i am retrieving the phone contacts and displaying them in list format.
I want to display the phone no and name of the particular person in next activity when i click on the list format contacts from first activity. I am getting errors in this its not able to perform click operation and display it on to next activity Please help me with this.</p>

<p>Here is the first Activity through i am display the contacts through content provider.</p>

<pre><code>import android.app.Activity;

import android.app.ListActivity;

import android.content.Intent;

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.provider.ContactsContract;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

import android.widget.SimpleCursorAdapter;

import android.widget.TextView;



public class MsatActivity extends ListActivity 

{

TextView ContactsTV;

ListView lv;

Cursor c;

public static final Uri CONTENT_URI = 

Uri.parse("content://com.android.contacts/contacts/1557");


public void onListItemClick(View v)

{

    Intent outData = new Intent(this,Full.class); 

//   setResult(Activity.RESULT_OK, outData);

     startActivity(outData);

}

  public void onCreate(Bundle savedInstanceState) 

  {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.main);

      Uri myContacts = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;         

      c = getContentResolver().query(myContacts, new String[]

      {ContactsContract.CommonDataKinds.Phone._ID,

      ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,

      ContactsContract.CommonDataKinds.Phone.NUMBER}     

      , null, null, null);


      String[] columns = new String[]                                   

              { 

              ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,

              ContactsContract.CommonDataKinds.Phone.NUMBER};        

             int[] to = new int[] {R.id.text1,R.id.text2};



            SimpleCursorAdapter mAdapter = new 

SimpleCursorAdapter(this,R.layout.listitems, c, columns, to); 

            setListAdapter(mAdapter); 

             lv.setOnItemSelectedListener(new OnItemClickListener() 

             {



public void onItemClick(AdapterView&lt;?&gt; parent, View view, int pos, long id) 

{

 int rowId = c.getInt(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone._ID));

Uri outURI = Uri.parse(CONTENT_URI.toString() + "/" + rowId); 

Intent outData = new Intent(); 

outData.setData(outURI);

 setResult(Activity.RESULT_OK, outData);

 finish();

 }

             });

  }

  }
</code></pre>

<p>Here is the second activity.......</p>

<pre><code>import android.app.Activity;

import android.content.Intent;

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.provider.ContactsContract;

import android.view.View;

import android.widget.Button;



public class Full extends Activity

{



    private static final int CONTACT_PICKER_RESULT = 1001;

    String name;

    Cursor cursor;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main1);

        Button getContacts = (Button)findViewById(R.id.button1);

        getContacts.setOnItemClickListener(new View.OnItemClickListener() 

        {



            public void onClick(View v)

            {

                Intent i = new Intent(Intent.ACTION_PICK,

                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);

                startActivityForResult(i, CONTACT_PICKER_RESULT);



            }

        });

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK)

        {

            switch (requestCode)

            {

            case CONTACT_PICKER_RESULT:





                try {

                    Uri result = data.getData();

                    String id = result.getLastPathSegment();



                    //Get Name

                    cursor = getContentResolver().query(result, null, null, null, null);

                    if (cursor.moveToFirst())

                    {

                        name = 
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

                    } 

                }

                    catch (Exception e) 

                    {



                    }

            }

        }

    }

}
</code></pre>
