What should I do to get my content provider to return the _count column with the count of records? The documentation says it is automatic, but maybe it's only taking about some built-in content provider. Running a query to the database seems not to return it.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
If you are using contentProvider then you have to do it like
count(*) AS count
.If you use
cursor.getCount()
, that would not be as efficient as the above approach. Withcursor.getCount()
you are fetching all the records just to get counts. The entire code should look like following -The reason why this works is because android needs a column name to be defined.
With
cursor.getCount()
you can not assure that it returns the real number of items returned. There are much better ways:1- If you are using Content Providers, you can do a query and use the
Column (_COUNT)
included in BaseColumns for your projection2- To do a rawQuery using
SELECT COUNT(*)
as @saurabh says in his response.If you are using
ContentProvider.query()
aCursor
is returned. CallCursor.getCount()
to get a count of records in the returned cursor.I had a similiar problem and found this worked for me. In the example below I wanted to get the count of images from the MediaStore provider.