我正在使用 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/