Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old May 29th, 2010, 09:38 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: May 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to use ListActivity but failing.

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>

Pov-Rev is offline  
Reply With Quote
sponsored links
Old May 31st, 2010, 07:28 PM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: May 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind I figured it out.
Pov-Rev is offline  
Reply With Quote
Old August 24th, 2010, 12:47 AM   #3 (permalink)
New Member
 
Join Date: Aug 2010
Posts: 6
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Pov-Rev View Post
Never mind I figured it out.
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.
adhavan is offline  
Reply With Quote
Old August 26th, 2010, 02:32 AM   #4 (permalink)
New Member
 
Join Date: Aug 2010
Location: Sweden
Posts: 13
 
Device(s): Motorola Milestone
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by adhavan View Post
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.
I suspect that the issue was that he didn't have a ListView with id @android:id/list, which is required by ListActivity.
meskiukas is offline  
Reply With Quote
Reply
Tags
create contact list, cursor, listview problems, simplecursoradapter


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:36 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.