AlertDialogを使用してデバッグ情報を表示しています。私は単に私が情報をドロップするリストを持っています。読みやすくするため、リストにある個々の項目の背景色を変更したいと考えています。残念ながら、私は保持したい色を得ることができません。AlertDialogでアダプタを使用するとAndroidが背景色を変える
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView tv = (TextView) v.findViewById(android.R.id.text1);
RuleDebugItem item = mData.get(position);
tv.setSingleLine(false);
if(item.type.equalsIgnoreCase(Field.VARIABLE)) {
tv.setText(item.ruleDebugText);
tv.setTextSize(18);
v.setBackgroundColor(color.bluelight);
tv.setTypeface(null, Typeface.BOLD);
tv.setTextColor(ContextCompat.getColor(mContext,android.R.color.white));
}
else if (item.type.equalsIgnoreCase(Field.FUNCTION)) {
tv.setText(item.ruleDebugText);
tv.setTextSize(16);
v.setBackgroundColor(color.greenlight);
tv.setTypeface(null, Typeface.BOLD);
tv.setTextColor(ContextCompat.getColor(mContext,android.R.color.white));
}
else if (item.type.equals("Condition")) {
tv.setText(" " + item.ruleDebugText);
tv.setTextSize(14);
tv.setTypeface(null, Typeface.NORMAL);
tv.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));
}
return v;
}
私はbackroundの色を変更するv.setBackgroundColor(color.greenlight);
を期待していた。ここで私が使用しているアダプターの図です。私は私自身のダイアログなどを構築することができると思いますが、おそらくそれはおそらく使い捨てのコードなので、これに多くの時間を費やしたくありませんでした。
ありがとうございました!
あなたは –
@Selvinように簡単に管理可能とすることができるonBindViewHolder方法でこれを変更することができますコードと進行中の作業を捨てると述べた。条件(およびその他の項目)は後で追加されます。 ArrayAdpaterとAlertDialogを使用して既に解決済みの場合は、私にリンクを送ってください。ありがとう。 –
Rahul - ArrayAdapterにはonBindViewHolderメソッドがないようです。あるいは私は何か違うことを提案していますか? –