2013-02-03 38 views
2

我正在爲使用android批註的android進行開發,但我並未展開如何將它與CursorAdapters配合使用。CursorAdapter中的AndroidAnnotations

目前已經是一個BaseAdapters例如,但如果我添加@EBean到一類範圍的CursorAdapter我得到錯誤信息「@EBean註釋元素應該有一個參數最大構造類型android.content的。上下文「。 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?

非常感謝提前。

回答

4

創建一個帶有一個參數(即上下文)的構造函數。

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

創建init方法並在init中爲適配器設置遊標。現在

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

你可以註釋SongInfoAdapter@EBean和使用的標註。