用于Android的ParseQueryAdapter不';t调用它的onload方法

用于Android的ParseQueryAdapter不';t调用它的onload方法,android,parse-platform,android-parsequeryadapter,Android,Parse Platform,Android Parsequeryadapter,我正在尝试自定义ParseQueryAdapter并实现缓存。我试图在适配器的onload方法中缓存结果,但问题是,正如在Logcat中看到的那样,onload和onload都不会被调用。当试图在实际活动中直接实现这两个方法时,会调用它们,但在这个单独的适配器类中实现它们时不会调用它们 这是我的代码: public class SongbookAdapter extends ParseQueryAdapter<Song> implements ParseQueryAdapter.On

我正在尝试自定义ParseQueryAdapter并实现缓存。我试图在适配器的onload方法中缓存结果,但问题是,正如在Logcat中看到的那样,onload和onload都不会被调用。当试图在实际活动中直接实现这两个方法时,会调用它们,但在这个单独的适配器类中实现它们时不会调用它们

这是我的代码:

public class SongbookAdapter extends ParseQueryAdapter<Song> implements ParseQueryAdapter.OnQueryLoadListener<Song> {

    private static String USERNAME = "username";
    private static String PIN_LABEL_SONGS = "songs";
    public Context context;

    public SongbookAdapter(final Context context, final ParseUser organizer) {
        super(context, new ParseQueryAdapter.QueryFactory<Song>() {
            public ParseQuery<Song> create() {
                ParseQuery<Song> query = ParseQuery.getQuery(Song.class);
                query.whereEqualTo(USERNAME, organizer.get(USERNAME));

                // If internet is down, we query from the cache in the local datastore
                if(!Methods.isOnline(context)) {
                    query.fromPin(PIN_LABEL_SONGS);
                }

                return query;
            }
        });

        this.context = context;

        Log.i("SongbookAdapter", "SongbookAdapter was created");
    }

    @Override
    public View getItemView(Song song, View v, ViewGroup parent) {
        ...
    }

    @Override
    public void onLoading() {
        Log.i("SongbookAdapter", "OnLoading was called");
    }

    @Override
    public void onLoaded(final List<Song> songs, Exception e) {
        Log.i("SongbookAdapter", "OnLoaded was called");
        if(e == null) {
            Log.i("SongbookAdapter", "Loading songs in adapter was successful");
            // If we have internet connection, we cache the results in the local datastore
            if(Methods.isOnline(context)) {
                cacheResults(songs);
            }
        } else {
            // Something went wrong
            Log.e("SongbookAdapter", "Loading songs in adapter failed");
            e.printStackTrace();
        }
    }
公共类SongbookAdapter扩展ParseQueryAdapter实现ParseQueryAdapter.OnQueryLoadListener{
私有静态字符串USERNAME=“USERNAME”;
私有静态字符串PIN_LABEL_SONGS=“SONGS”;
公共语境;
公共SongbookAdapter(最终上下文、最终用户管理器){
super(上下文,新的ParseQueryAdapter.QueryFactory(){
公共ParseQuery创建(){
ParseQuery=ParseQuery.getQuery(Song.class);
query.whereEqualTo(用户名,组织者.get(用户名));
//如果internet关闭,我们将从本地数据存储中的缓存进行查询
if(!Methods.isOnline(上下文)){
query.fromPin(PIN\u标签\u歌曲);
}
返回查询;
}
});
this.context=上下文;
Log.i(“SongbookAdapter”,“SongbookAdapter已创建”);
}
@凌驾
公共视图getItemView(歌曲、视图v、视图组父级){
...
}
@凌驾
公共无效加载(){
i(“SongbookAdapter”,“调用onload”);
}
@凌驾
已加载公共void(最终列表歌曲,例外e){
i(“SongbookAdapter”,“调用onload”);
如果(e==null){
Log.i(“SongbookAdapter”,“在适配器中加载歌曲成功”);
//如果我们有internet连接,我们将结果缓存在本地数据存储中
if(Methods.isOnline(上下文)){
缓存结果(歌曲);
}
}否则{
//出了点问题
Log.e(“SongbookAdapter”,“在适配器中加载歌曲失败”);
e、 printStackTrace();
}
}
日志:

W/KeyCharacterMap﹕ No keyboard for id -1
W/KeyCharacterMap﹕ Using default keymap: /system/usr/keychars/qwerty.kcm.bin
D/SongbookAdapter﹕ SongbookAdapter was created
D/dalvikvm﹕ GC_FOR_MALLOC freed 1074K, 47% free 4858K/9095K, external 3496K/4366K, paused 20ms
I/dalvikvm-heap﹕ Grow heap (frag case) to 11.465MB for 844153-byte allocation
D/dalvikvm﹕ GC_FOR_MALLOC freed <1K, 43% free 5682K/9927K, external 3496K/4366K, paused 60ms
D/dalvikvm﹕ GC_FOR_MALLOC freed 1491K, 48% free 5166K/9927K, external 3119K/3895K, paused 15ms
D/dalvikvm﹕ GC_FOR_MALLOC freed 515K, 43% free 5675K/9927K, external 3119K/3895K, paused 16ms
I/dalvikvm-heap﹕ Grow heap (frag case) to 11.895MB for 844153-byte allocation
D/dalvikvm﹕ GC_FOR_MALLOC freed 0K, 40% free 6500K/10759K, external 3119K/3895K, paused 15ms
D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 1017K, 50% free 5483K/10759K, external 3119K/3895K, paused 22ms
D/szipinf﹕ Initializing inflate state
W/KeyCharacterMap﹕ id-1没有键盘
W/KeyCharacterMap﹕ 使用默认键映射:/system/usr/keychars/qwerty.kcm.bin
D/SongbookAdapter﹕ SongbookAdapter已创建
D/dalvikvm﹕ GC_FOR_MALLOC释放1074K,47%释放4858K/9095K,外部3496K/4366K,暂停20ms
I/VM堆﹕ 为844153字节分配将堆(frag大小写)增加到11.465MB

D/dalvikvm﹕ GC_FOR_MALLOC freed找到了我问题的答案-我忘记在构造函数中添加onQueryLoadListener。因此,正确的构造函数是:

public SongbookAdapter(final Context context, final ParseUser organizer) {
    super(context, new ParseQueryAdapter.QueryFactory<Song>() {
        public ParseQuery<Song> create() {
            ParseQuery<Song> query = ParseQuery.getQuery(Song.class);
            query.whereEqualTo(USERNAME, organizer.get(USERNAME));

            // If internet is down, we query from the cache in the local datastore
            if(!Methods.isOnline(context)) {
                query.fromPin(PIN_LABEL_SONGS);
            }

            return query;
        }
    });

    this.context = context;

    // This it what I forgot
    addOnQueryLoadListener(this);

    Log.i("SongbookAdapter", "SongbookAdapter was created");
}
publicsongbookadapter(最终上下文,最终用户管理器){
super(上下文,新的ParseQueryAdapter.QueryFactory(){
公共ParseQuery创建(){
ParseQuery=ParseQuery.getQuery(Song.class);
query.whereEqualTo(用户名,组织者.get(用户名));
//如果internet关闭,我们将从本地数据存储中的缓存进行查询
if(!Methods.isOnline(上下文)){
query.fromPin(PIN\u标签\u歌曲);
}
返回查询;
}
});
this.context=上下文;
//这是我忘记的
addOnQueryLoadListener(此);
Log.i(“SongbookAdapter”,“SongbookAdapter已创建”);
}

谢谢你,先生,你救了我一天