String address = 0123456789;

Cursor unreadcountcursor = getContentResolver().query(Uri.parse("content://sms/inbox"),
new String[]{}, "read = 0 and address='"+address+"'", null, null);

int count = unreadcountcursor.getCount();


没有更快的获取方式吗?因为当您需要对许多数字进行计数时,该代码执行起来很繁琐,因此加载时间很长。还有另一种方法,假设此代码将处于while循环中。我知道在适配器中使用它会更快,更可行,但是适配器的问题是我必须滚动列表并返回计数以获取更新,notifyDataSetChanged()对此没有任何作用。

最好的解决方案是什么?

谢谢。

最佳答案

我不确定这会浪费很多设备时间,但肯定会浪费您的时间:

 Cursor countCursor = getContentResolver().query(CONTENT_URI,
                "count(*) AS count",
                null,
                null,
                null);

        countCursor.moveToFirst();
        int count = countCursor.getInt(0);


引自here

09-28 06:36