Android 将游标装入器与联接一起使用
有两个表:高分表和高分表引用玩家表的PlayerID的玩家。我正在使用cursorLoader加载数据。我不知道如何使用游标加载器,以便它从球员id处于高分的球员那里返回球员姓名 我无法从中理解答案 , . 我需要使用一个新的Uri,但我不知道如何创建它。 下面是表列和游标加载器查询Android 将游标装入器与联接一起使用,android,join,android-cursorloader,Android,Join,Android Cursorloader,有两个表:高分表和高分表引用玩家表的PlayerID的玩家。我正在使用cursorLoader加载数据。我不知道如何使用游标加载器,以便它从球员id处于高分的球员那里返回球员姓名 我无法从中理解答案 , . 我需要使用一个新的Uri,但我不知道如何创建它。 下面是表列和游标加载器查询 package colormemory.com.androidrecyclerviewgridview.model.DB; import android.net.Uri; import android.provi
package colormemory.com.androidrecyclerviewgridview.model.DB;
import android.net.Uri;
import android.provider.BaseColumns;
public final class ColorGameContract {
// Authority identifier for the player content
public static final String AUTHORITY = "com.colormemory.PlayersProvider";
// URL to communicate with the player content provider
private static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY);
public static final class Player
implements BaseColumns {
public static String PLAYER_TABLE_NAME = "players";
public static final Uri PLAYER_CONTENT_URI =
BASE_URI.buildUpon()
.appendPath(PLAYER_TABLE_NAME)
.build();
public static final String COLUMN_SCORE = "score";
public static final String COLUMN_NAME = "name";
}
public static final class HighScore
implements BaseColumns {
public static String HIGHSCORE_TABLE_NAME = "HighScore";
public static final Uri HIGHSCORE_CONTENT_URI =
BASE_URI.buildUpon()
.appendPath(HIGHSCORE_TABLE_NAME)
.build();
public static final String COLUMN_SCORE = "score";
public static final String COLUMN_PLAYERID = "playerId";
}
}
@覆盖
公共加载器onCreateLoader(最终int-id,最终Bundle-args){
开关(id){
案例加载器\u ID:
字符串URL=PlayerProvider.HighScoreURL;
urihighscoreuri=Uri.parse(URL);
字符串[]投影={
//ColorGameContract.Player.COLUMN\u名称,
ColorGameContract.HighScore.COLUMN_SCORE};
//final Uri=Uri.parse(“content://some_uri");
//最终Uri=播放器内容Uri;
返回新的游标装入器(this,highScoreUri,PROJECTION,null,null,null);
}
使用String URL=PlayersProvider.HighScoreWithJoinURL;
…并在ContentProvider
中添加实现,这将处理这个问题。我知道了!这对我很有用。一旦我有了这个想法,这很容易。@user4057066你能用你的解决方案发布一个答案吗?我正在使用别人编写的代码(而且我对游标加载程序不太了解)我也有同样的问题,完全不知道如何编写连接…使用String URL=PlayersProvider.HighScoreWithJoinURL;
…并在ContentProvider
中添加实现,它将处理这个问题。Urigit!对我来说很有用。一旦我有了这个想法,就很容易了。@user4057066您能用您的解决方案发布一个答案吗ion?我正在处理别人编写的代码(我对游标加载程序不太了解),我也有同样的问题,根本不知道如何编写连接。。。
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
switch (id) {
case LOADER_ID:
String URL = PlayersProvider.HighScoreURL;
Uri highScoreUri = Uri.parse(URL);
String[] PROJECTION = {
//ColorGameContract.Player.COLUMN_NAME,
ColorGameContract.HighScore.COLUMN_SCORE};
//final Uri uri = Uri.parse("content://some_uri");
//final Uri uri = PLAYER_CONTENT_URI;
return new CursorLoader(this, highScoreUri, PROJECTION, null, null, null);
}