1. Welcome to the newer, better version of Android Forums! Be sure to see the announcement and enjoy checking it out!

    Some of you have been having login issues. - Please try now. Sorry for the trouble!
  2. All attachments uploaded on the first day of this new look need to be re-uploaded, or will appear broken. All prior to that, and all going forward, should work fine. We apologize for the inconvenience!

Trying to use ListActivity but failing.


  1. Pov-Rev

    Pov-Rev New Member

    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 {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_main);


    ContentResolver cR = getContentResolver();

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

    }


    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>
    </RelativeLayout>


    contact_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

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

    Advertisement
  2. Pov-Rev

    Pov-Rev New Member

    Never mind I figured it out.
  3. adhavan

    adhavan Member

    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 Member

    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