リスト項目用のカスタム アダプターを実装しました。2つの要件があります
1) リスト項目には別の色が必要です。それを実装するために、私は以下のコードを持っています
private final int[] bgColors = new int[] {R.color.list_bg_1, R.color.list_bg_2};
int colorPosition = position % bgColors.length;
convertView.setBackgroundResource(bgColors[colorPosition]);
2)リスト項目をクリックすると、強調表示されます
Drawable selectedBackground;
selectedBackground = context.getResources().getDrawable(R.color.backgroundColor);
if (selectedPos == position) {
convertView.setBackgroundDrawable(selectedBackground);
} else {
convertView.setBackgroundDrawable(null);
}
// this method is called in onItemClick in Activity.
public void setSelectedPosition(int pos){
selectedPos = pos;
notifyDataSetChanged();
}
問題: 両方のコードを配置すると、どちらかの機能が動作しません。両方の機能が上記のコードで動作することを確認するにはどうすればよいですか?