CursorAdapter中的AndroidAnnotations

时间:2013-02-03 11:40:35

标签: 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?

非常感谢提前。

1 个答案:

答案 0 :(得分:4)

创建一个带有一个参数的构造函数,即上下文。

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

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

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

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