Hi All,
I just copied this code from the web and trying to run it in Eclipse gives
me errors, the R.id.listView and R.layout.main are not getting resolved. No
idea whats going wrong here.
Please find the code for Java and mail.xml file as below:
---------------------------------------------------MyContentResolver .java
file is below:
package com.sailo.contentresolverdemo;

import java.util.ArrayList;

import android.R;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MyContentResolver extends Activity {
 private static final String TAG = "MyContentResolver";
private ArrayList<String> list;

/** Called when the activity is first created. */
@Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

// Get content provider and cursor
 ContentResolver r = getContentResolver();
Cursor cursor = r.query(ContactsContract.Contacts.CONTENT_URI, null,
 null, null, null);

// Let activity manage the cursor
startManagingCursor(cursor);
 Log.d(TAG, "cursor.getCount()=" + cursor.getCount());

// Get value from content provider
 int nameIndex = cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME);
int numberIndex = cursor
 .getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);

cursor.moveToFirst();
 list = new ArrayList<String>();
do {
String name = cursor.getString(nameIndex);
 String number = cursor.getString(numberIndex);
list.add(name + ": " + number);
 } while (cursor.moveToNext());

// Get the list view
ListView listView = (ListView) findViewById(R.id.listView);
 ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
 listView.setAdapter(aa);
}
}

---------------------------------------------------- main.xml is given
below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    />
</LinearLayout>

-----------------------------------------------



Thanks in advance.

Thanks,
KK

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to