java - 轻松使用 CursorLoader

标签 java android android-cursor android-cursorloader

我尝试使用 CursorLoader,但我不明白如何填写参数。

对于我的应用程序,我需要在一列中观察该值是否为 false 并获取该行的 id。

     String[] projection = { 
         TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE
         };        


Context context = this;
Uri uri = IsansysPatientGatewayContentProvider.CONTENT_URI_RESPIRATION_RATES;
String selection = TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE ;
String[] selectionArgs = null;
String sortOrder = null;

    cursorLoader = new CursorLoader(context, uri, projection, selection + "=?", selectionArgs, sortOrder);

在 SQL 中它看起来像这样:

SELECT id FROM TableLifetouchRespirationRate WHERE acknolegment_message = false

你能给我一个使用游标加载器的例子吗?

最佳答案

我找到了自己:)

    Context context = this;
// URI table
Uri uri = IsansysPatientGatewayContentProvider.CONTENT_URI_RESPIRATION_RATES;
// URI columns to get from table class
String[] projection = { 
        TableLifetouchRespirationRate.COLUMN_ID, 
        TableLifetouchRespirationRate.COLUMN_LIFETOUCH_ID, 
        TableLifetouchRespirationRate.COLUMN_RESPIRATION_RATE,
        TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE, 
        TableLifetouchRespirationRate.COLUMN_TIMESTAMP,
        TableLifetouchRespirationRate.COLUMN_SESSION_NUMBER
        };       
// In the column ACKNOWLEDGMENT_MESSAGE...
String selection = TableLifetouchRespirationRate.COLUMN_ACKNOWLEDGMENT_MESSAGE  + "=?"; 
// Select rows = "0" (it is possible to add augments on several columns)
String[] selectionArgs = {"0"};
String sortOrder = null;

cursorLoader = new CursorLoader(context, uri, projection, selection, selectionArgs, sortOrder);

玩得开心!

关于java - 轻松使用 CursorLoader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23361390/

相关文章:

java - Spring Security 404 静态资源

Java 并发数 : resettable enabled/disabled wait condition

android - SurfaceView 在 surfaceChange Android 上崩溃

android - 在用户不知情的情况下使用前置摄像头拍摄照片

android - 我如何在游标中使用子字符串?

java - 对 main() 中的函数进行 JUnit 测试

java - Log4j - 寻找好的 'Getting started' 教程或博客

android - 如何使用 JWT token 发送 HTTP 请求以从 android 中的 cookie 存储进行身份验证

两个日期之间的 Android 通话记录数据和来自同一号码的通话总时长。

android - 在 CursorAdapter 中更改光标