使用CursorLoader和Join

时间:2016-11-30 15:35:37

标签: android join android-cursorloader

有2个表:高分和高分玩家表引用玩家表的玩家ID。我正在使用cursorLoader加载数据。我不确定如何使用游标加载器,以便从玩家ID为高分的玩家返回玩家名称。

我无法理解答案 Join Two tables and get the cursor for Cursorloaderhow to use join query in CursorLoader when its constructor does not support it。 我需要使用新的Uri,但我不确定如何创建它。 下面是表列和游标加载器查询。

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";
}

}

 @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);
    }

0 个答案:

没有答案