0
import android.app.Activity;
import android.os.Bundle;
import android.app.ListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Uri allContacts = Uri.parse("content://contacts/people");
            Cursor c = managedQuery(allContacts, null, null, null, null);
            String[] columns = new String[] {
            ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts._ID};
            int[] views = new int[] {R.id.contactName, R.id.contactID};
            SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(this, R.layout.activity_main, c, columns,views);    
            this.setListAdapter(adapter);
    }

}

它总是显示此错误:方法 setListAdapter(SimpleCursorAdapter) 未定义 MainActivity 类型

4

2 回答 2

4

为了使用setListAdapter你的类必须扩展ListActivitynot Activity。改变

public class MainActivity extends Activity

public class MainActivity extends ListActivity 
于 2013-07-07T09:13:00.000 回答
0

用extends ListActivity更改extends Activity后,如果问题还没有结束,可以尝试更改:

import android.widget.SimpleCursorAdapter;

和:

import android.support.v4.widget.SimpleCursorAdapter;

于 2015-08-29T12:57:05.027 回答