问题描述
- android利用SimpleCursorAdapter获取联系人数据只能显示一部分
- 这是书上的一个例子,但是没能获取全部的联系人列表,只获取了一部分,求解
public class MyActivity extends ListActivity {@Overridepublic 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 columsviews); }else{ sca=new SimpleCursorAdapter(this R.layout.test c colums views CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); } this.setListAdapter(sca);}
}
时间: 2024-11-02 02:38:27