adding to database from listview using onitemclick
<p>i have displayed contact names and phoneno in listview using the code attached .</p>

<p>now using onitemclick i want to add the phoneno only from the position i click to the database i have created named MyDatabase and its connection name is MyConnection.</p>

<p>but i dont know how to get only phone no from listview when i click and avaoid the name of contact.</p>

<pre><code>public class PhonebookBL extends Activity implements OnItemClickListener  {

ListView lv;
MyConnection con;
String phoneNo;

ArrayAdapter&lt;String&gt; ad;
ArrayList&lt;String&gt; list;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.phonebookbl);
    list = new ArrayList&lt;String&gt;();
    lv = (ListView) findViewById(R.id.listViewPhonebookBL);
    lv.setOnItemClickListener(this);

    try {
        con = MyConnection.connectionFactory(this);
        displaycontacts();
        onResume();
    } catch (SQLException e) {
        // TODO: handle exception
    }
}

private ArrayList&lt;String&gt; displaycontacts() {
    // TODO Auto-generated method stub
    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, null);
    if (cur.getCount() &gt; 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(cur
                    .getColumnIndex(ContactsContract.Contacts._ID));
            String name = cur
                    .getString(cur
                            .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer
                    .parseInt(cur.getString(cur
                            .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
                Cursor pCur = cr.query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                + " = ?", new String[] { id }, null);
                while (pCur.moveToNext()) {
                    phoneNo = pCur
                            .getString(pCur
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                    list.add(name + "   " + phoneNo);
                }
                pCur.close();
            }



        }
    }
    return list;
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    ArrayAdapter&lt;String&gt; ad = new ArrayAdapter&lt;String&gt;(getApplicationContext(), android.R.layout.simple_list_item_1, list);
    lv.setAdapter(ad);

}

@Override
public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

}}
</code></pre>

<p>xml file is this</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bacgroundmain"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PhonebookBL" &gt;

&lt;ListView
    android:id="@+id/listViewPhonebookBL"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" &gt;
&lt;/ListView&gt;
</code></pre>

<p></p>
