Java 内容提供程序列表视图限制
我想限制我的应用程序中显示的联系人数量。目前它正在查询my Contacts Contract.Contacts DB并返回每个具有电话号码的主显示名称。有没有一种简单的方法可以将其减少到一个数字量,比如只显示5个联系人,或者减少到特定的ID 这就是我到目前为止所做的:Java 内容提供程序列表视图限制,java,android,android-listview,android-fragmentactivity,Java,Android,Android Listview,Android Fragmentactivity,我想限制我的应用程序中显示的联系人数量。目前它正在查询my Contacts Contract.Contacts DB并返回每个具有电话号码的主显示名称。有没有一种简单的方法可以将其减少到一个数字量,比如只显示5个联系人,或者减少到特定的ID 这就是我到目前为止所做的: public Loader<Cursor> onCreateLoader(int id, Bundle args) { // load from the "Contacts table" U
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// load from the "Contacts table"
Uri contentUri = ContactsContract.Contacts.CONTENT_URI;
// no sub-selection, no sort order, simply every row
// projection says we want just the _id and the name column
return new CursorLoader(getActivity(),
contentUri,
PROJECTION,
ContactsContract.Contacts.HAS_PHONE_NUMBER + " =?", // This is selection string, were looking for records that HAS_PHONE_NUMER is 1
new String[]{"1"}, // 1 means that contact has a phone number
ContactsContract.Contacts._COUNT,
new String[] {"5"},
null);
}
干杯,
Shyam要限制查询结果,请在查询中添加字符串连接限制5:
...
ContactsContract.Contacts.HAS_PHONE_NUMBER + "=? LIMIT 5" //This is selection string, were looking for records that HAS_PHONE_NUMER is 1 AND
// the result set is limited to 5 rows
new String[]{"1"},
null);
...
答案是否取决于创建arraylist,然后applybatch删除所有不需要的项?谢谢-这似乎是我需要使用的方法。然而,由于某些原因,每当我查询计数时,应用程序就会不断崩溃。我已经确保在我的投影初始化中也包含了它。您知道可能完成此任务的其他变量吗?最新,@Shyam,请参阅:,
...
ContactsContract.Contacts.HAS_PHONE_NUMBER + "=? LIMIT 5" //This is selection string, were looking for records that HAS_PHONE_NUMER is 1 AND
// the result set is limited to 5 rows
new String[]{"1"},
null);
...