1
私はアダプタを持っており、色の配列とテキストの配列を渡します>色の配列の項目を表示しませんか?なぜアダプタが色配列を表示できないのですか?
public class HoursFromToAdapter extends BaseAdapter{
private Context context;
private String[] mHoursRenge;
private int[] mColors;
private TextView mHoursRangeTxt;
private CardView mCardView;
public HoursFromToAdapter(Context context, String[] hoursRenge , int[] colors) {
this.context=context;
this.mHoursRenge=hoursRenge;
this.mColors=colors;
}
@Override
public int getCount() {
/*return number of elements inside this array*/
return mHoursRenge.length;
}
@Override
public Object getItem(int position) {
/*return the item at posion -position-*/
return null;
}
@Override
public long getItemId(int position) {
/*return the id of the row which in this case the index of the array*/
return 0;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.day_item,parent,false);
View v;
LinearLayout ln;
if(convertView == null) {
v = new View(context);
v = inflater.inflate(R.layout.day_item, null);
ln=(LinearLayout)v.findViewById(R.id.card_containner);
mHoursRangeTxt= (TextView) v.findViewById(R.id.text_hours_from_to);
mHoursRangeTxt.setText(mHoursRenge[position]);
mCardView=(CardView)v.findViewById(R.id.card_day_item);
mCardView.setCardBackgroundColor(mColors[position]);
}else {
v = convertView;
}
return v;
}
}
私は別のクラスからの色の配列を渡すとき、それは表示されませんが、テキストの配列が
も
String hoursArray[]={"7 am : 8 am" ,"8 am : 9 am","9 am : 10 am","10 am : 11 am","11 am : 12 pm","12 pm : 1 pm","1 pm : 2 pm","2 pm : 3 pm"};
int colorsArray[]={R.color.colorOrange,R.color.colorRed,R.color.colorOrange,R.color.colorOrange,R.color.colorRed,R.color.colorOrange,R.color.colorRed,R.color.colorOrange};
mHoursFromToAdapter=new HoursFromToAdapter(HomeActivity.this,hoursArray,colorsArray);
を表示cardView上の色の配列を表示することができないの問題は何ですか?
感謝を
if else
句の外を移動し、ホルダーのパターンを実装します –