2 u013538630 u013538630 于 2014.08.09 15:34 提问

android利用SimpleCursorAdapter获取联系人数据只能显示一部分

这是书上的一个例子,但是没能获取全部的联系人列表,只获取了一部分,求解

public class MyActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    Uri allContacts=Uri.parse("content://contacts/people");
    Cursor c;
    if(Build.VERSION.SDK_INT<11){

        c=managedQuery(allContacts,
                null,
                null,
                null,
                null
                );
    }else {
        CursorLoader cursorLoader = new CursorLoader(
                this,
                allContacts,
                null,
                null,
                null,
                null
        );
        c=cursorLoader.loadInBackground();
    }
    String[] colums=new String[]{
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.Contacts._ID
    };
    int []views=new int[]{
            R.id.contactName,
            R.id.phone
    };
    c.moveToFirst();
    SimpleCursorAdapter sca;
    if(Build.VERSION.SDK_INT<11){
        sca=new SimpleCursorAdapter(this, R.layout.test, c, colums,views);
    }else{
        sca=new SimpleCursorAdapter(this, R.layout.test, c, colums, views, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    }

    this.setListAdapter(sca);
}

}

Csdn user default icon
上传中...
上传图片
插入图片