私はAndroidの初心者です。
ExpandableListView アダプター内でカスタム カラーを設定しようとしています。colors.xml で色を定義しましたが、アダプターで使用できません。「メソッド getResources() は、タイプ ExpandableListAdapter に対して定義されていません」というエラーが表示されます。
この関数は int を想定しています。getResources からの結果を渡そうとしましたが、うまくいきません。16 進数値も渡そうとしましたが、何も変わりません。
コードでカスタム カラーを使用するにはどうすればよいですか?
public View getGroupView(int groupPosition, boolean arg1, View convertView,
ViewGroup arg3) {
int n = 0;
String laptopName = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item, null);
}
TextView item = (TextView) convertView.findViewById(R.id.demo);
item.setTypeface(null, Typeface.BOLD);
item.setText(laptopName);
convertView.setBackgroundColor(getResources().getColor(R.color.purple));
return convertView;
}
みんなありがとう、次のスニペットは機能します
this.context = (Activity) context;
convertView.setBackgroundColor(this.context.getResources().getColor(R.color.purple));