• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Trying to use ListActivity but failing.

Pov-Rev

Lurker
May 28, 2010
2
0
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>
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones