Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 装载机<;光标>;仅加载选定行+;下一排_Android_Sqlite_Android Sqlite_Android Cursorloader_Android Loader - Fatal编程技术网

Android 装载机<;光标>;仅加载选定行+;下一排

Android 装载机<;光标>;仅加载选定行+;下一排,android,sqlite,android-sqlite,android-cursorloader,android-loader,Android,Sqlite,Android Sqlite,Android Cursorloader,Android Loader,在活动A中,我正在加载一个包含表中所有值的列表,并已设置一个setOnItemClickListener,以启动活动B,并通过发送数据发送一个带有所选项目id[1]的uri [1] uricurrenttesturi=ContentUris.withAppendedId(TestEntry.CONTENT\u Uri,id) 在活动B中,我的onCreateLoader带有投影: String[] projection = { TestEntry._ID, TestE

活动A中,我正在加载一个包含表中所有值的列表,并已设置一个setOnItemClickListener,以启动活动B,并通过发送数据发送一个带有所选项目id[1]的uri

[1]
uricurrenttesturi=ContentUris.withAppendedId(TestEntry.CONTENT\u Uri,id)

活动B中,我的onCreateLoader带有投影:

String[] projection = {
       TestEntry._ID,
       TestEntry.COLUMN_TEST_ONE,
       TestEntry.COLUMN_TEST_TWO}
…返回语句

return new CursorLoader(this,  
    mCurrentTestUri, //Got this from Activity A         
    projection,             
    null,                   
    null,                   
    null);  
我的onLoadFinished看起来像这样:

if (cursor.moveToFirst()) {
      int oneColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_ONE);
      int twoColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_TWO);

      String currentOne = cursor.getString(oneColumnIndex);
      String currentTwo = cursor.getString(twoColumnIndex);

      textViewOne.setText(currentOne);
      textViewTwo.setText(currentTwo);
}

到目前为止还不错,现在我希望显示下一行的值(就在它的正下方),但是使用不同的投影(我只需要
\u ID
列测试\u ONE
)并在
文本视图三中显示列测试一的值

[两行中的值应同时显示,而不是一行或多行 另一个]

我可以通过[2]从活动A中获取下一行的ID,并通过putExtra将其作为字符串发送,但到目前为止,这就是我所拥有的全部

[2]

String nextItemId = String.valueOf(listView.getItemIdAtPosition(position + 1));
if((position+1) < lListView.getCount()) {
    intent.putExtra("prevID", nextItemId);
}
如何更改活动B以从下一行加载值 和当前的onCreate?


问题在于您的查询:


    Uri currentTestUri = ContentUris.withAppendedId(TestEntry.CONTENT_URI, id);
这里您指定只查询具有特定
id
行。任何具有不同
id
的行都不会在
光标中返回

而是使用适当的选择参数查询表:


    // Load all rows that have id `firstId` or `secondId`
    return new CursorLoader(this,  
        TestEntry.CONTENT_URI,
        projection,             
        TestEntry._ID + "=? OR " + TestEntry._ID + "=?",                   
        new String[] {firstId, secondId},                   
        null);
然后您可以通过以下方式获得
secondId
行的值:


    if (cursor.moveToFirst()) {
          ...

          textViewOne.setText(currentOne);
          textViewTwo.setText(currentTwo);

          if (cursor.moveToNext()) {
              int index = cursor.getColumnIndex(TestEntry.COLUMN_TEST_ONE);
              String next = cursor.getString(index);
              // Use `next` as needed, may be passed to next activity via extras
          }
    }

“同时”是什么意思?“你能说出那部分吗?@azizbekian my bad,不完全是在同一时间(如字面意思),但当活动开始(onCreate)时,效果非常好!非常感谢。只能在明天奖励赏金,但在这里,在那之前先拿+1!很高兴这对你有用。请不要立即奖励赏金,也许有人会想出更好的解决办法。只要这是一个选定的答案-赏金将自动奖励,不用担心。

    if (cursor.moveToFirst()) {
          ...

          textViewOne.setText(currentOne);
          textViewTwo.setText(currentTwo);

          if (cursor.moveToNext()) {
              int index = cursor.getColumnIndex(TestEntry.COLUMN_TEST_ONE);
              String next = cursor.getString(index);
              // Use `next` as needed, may be passed to next activity via extras
          }
    }