1. Are you ready for the Galaxy S20? Here is everything we know so far!

Trying to use ListActivity but failing.

Discussion in 'Android Development' started by Pov-Rev, May 29, 2010.

  1. Pov-Rev

    Pov-Rev Lurker
    Thread Starter

    This is driving me nuts I just can't seem to get this to work right, all I want to do is to query the contact list and get a list of all the display names and phone numbers, I am attempting to run this on a Motorola Droid with Android 2.1. I have done other simple programs and they have all worked out great but I just can't for the life of me figure out what I am doing wrong with this Listview, SimpleCursorAdapter and Cursor query. Can anyone tell me what I am doing wrong or does anyone have working code that shows me what to do?

    Thanks for you help.

    Here is my code:

    import android.app.ListActivity;
    import android.content.ContentResolver;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.Contacts.People;
    import android.provider.ContactsContract.CommonDataKinds.Phone;
    import android.widget.SimpleCursorAdapter;

    public class JNContact_List extends ListActivity {

    public void onCreate(Bundle savedInstanceState) {

    ContentResolver cR = getContentResolver();

    Cursor c = cR.query(People.CONTENT_URI, new String[] {People._ID, People.NAME, People.NUMBER}, null, null , null);
    SimpleCursorAdapter oSCA = new SimpleCursorAdapter(this, R.layout.contact_row, c, new String[] {Phone.NUMBER}, new int[] {R.id.TextView01} );


    contact_row.xml :

    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="3dip"></TextView>

    <TextView android:text="@+id/TextView02" android:id="@+id/TextView02" android:layout_height="wrap_content" android:layout_toRightOf="@+id/TextView01" android:layout_width="wrap_content" android:layout_below="@+id/TextView01" android:layout_alignParentLeft="true" android:layout_marginTop="3dip"></TextView>

    <Button android:id="@+id/Button01" android:layout_toRightOf="@+id/TextView01" android:layout_width="50dip" android:layout_height="50dip" android:text="Call"></Button>


    <?xml version="1.0" encoding="utf-8"?>

    <ListView android:id="@+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>

    1. Download the Forums for Android™ app!


  2. Pov-Rev

    Pov-Rev Lurker
    Thread Starter

    Never mind I figured it out.
  3. adhavan

    adhavan Lurker

    hey please post the solution that u did, that will be useful for me to solve my issue.
    i am facing a problem in inserting and deleting a contact.
  4. meskiukas

    meskiukas Newbie

    I suspect that the issue was that he didn't have a ListView with id @android:id/list, which is required by ListActivity.

Share This Page