android-annotations - CursorAdapter 中的 AndroidAnnotations

标签 android-annotations

我正在使用 Android 注释进行 Android 开发,但我不明白如何将它与 CursorAdapters 一起使用。

已经有 BaseAdapters 的示例,但是如果我将 @EBean 添加到扩展 CursorAdapter 的类中,我会收到错误消息“@EBean 带注释的元素应该有一个带有一个 max 参数、类型为 android.content.Context 的构造函数”。 CursorAdapter 已经有两个构造函数。

public class SongInfoAdapter extends CursorAdapter {
...
@Override
public void bindView(View view, Context context, Cursor cursor) {
 ...
 rowData.id.setOnClickListener(new OnClickListener() {
     public void onClick(View v) { 
         itemOnClick(rowData);
     }
 });
}

public void itemOnClick(RowDataHolder rowData) {
    switch(audioPlayer.getPlayingplayer()) {
    case AudioPlayer.RIGHT:
    case AudioPlayer.NONE:
        audioPlayer.load(rowData.songInfo, AudioPlayer.LEFT);
        break;
    case AudioPlayer.LEFT:
        audioPlayer.load(rowData.songInfo, AudioPlayer.RIGHT);  
        break;
    }
}
...
}

AudioPlayer是一个使用注释的类(@EBean),但我不会写

@Bean
AudioPlayer audioPlayer;

因为我不能在这个类中使用注释。如何在 CursorAdapter 中使用 AndroidAnnotations?

提前非常感谢。

最佳答案

创建一个接受一个参数(即上下文)的构造函数。

SongInfoAdapter (Context context) {
    super(context, null, FLAG_AUTO_REQUERY);
}

创建一个init方法并在init中设置适配器的光标。

public void init(Cursor c) {
    this.changeCursor(c);
}

现在您可以使用 @EBean 注释 SongInfoAdapter 并使用注释。

关于android-annotations - CursorAdapter 中的 AndroidAnnotations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14672069/

相关文章:

Android注解REST发送图像

android - Gradle构建由于androidannotations插件而失败

java - 什么会导致错误 : Could not find the AndroidManifest. xml 文件?

android - Gradle + AndroidAnnotations 生成重复的类错误 - 需要在每次构建之前清理项目

android - Dagger 2 和 Android Annotations 可以一起工作吗?

Android 注释 gradle 警告

android - RequiresApi vs TargetApi android注解

java - 注释回收器查看 ItemClick

java - 如何访问android注解sharedPreference?

android - 注释:@EViewGroup - Android 库模块中的注释参数必须是编译时常量错误