Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to dynamically add text view to the list view in android?
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/103te.png" alt="enter image description here"></p> <p>I need to add two text view to the list view as shown in figure..what I need is that on the click of contact button the name and the type of number get automatically into my own list view..I am not been able to add text view to the list view because of that I am only able to see phone's contact list...kindly help me please..thanks in advance..here is the code.</p> <pre><code>import android.app.ListActivity; import android.os.Bundle; import android.provider.ContactsContract; import android.content.Intent; import android.database.Cursor; public class TestActivity extends ListActivity { private static final int PICK_CONTACT = 0; /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //content uri provide directory of people Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(intentContact, PICK_CONTACT); }//onCreate public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode ==PICK_CONTACT) { getContactInfo(intent); } }//onActivityResult protected void getContactInfo(Intent intent) { String name; Cursor cursor = managedQuery(intent.getData(), null, null, null, null); while (cursor.moveToNext()) { //contains row id String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); //whether contact list atleast have a single contact or not String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); if ( hasPhone.equalsIgnoreCase("1")) hasPhone = "true"; else hasPhone = "false" ; if (Boolean.parseBoolean(hasPhone)) { Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null); while (phones.moveToNext()) { String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); }//end phones.close(); }//end cursor.close(); }//end while }//end method }//end class........... </code></pre> <p>this is xml file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;TextView android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/LinearLayout&gt;........ &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent"&gt; &lt;TextView android:id="@+id/toptext" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center_vertical" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:id="@+id/bottomtext" android:singleLine="true" android:ellipsize="marquee" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload