您好,在此先感谢您,
有没有办法改变特定单元格的背景颜色?即按索引号?我正在尝试通过添加 - if(position==3) 来修改下面的本教程代码。不知道我做错了什么,或者它是否被允许。任何帮助是极大的赞赏。
public ItemListBaseAdapter(Context context, ArrayList < ItemDetails > results) {
itemDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
}
public int getCount() {
return itemDetailsrrayList.size();
}
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.item_details_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);
// holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.price);
holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//////////////////////////// TEST CODE - Header cells ////////////////
if(position == 2){
convertView.setBackgroundColor(android.R.color.background_light);
}
if (position == 3) {
convertView.setBackgroundColor(android.R.color.background_light);
}
if (position == 14) {
convertView.setBackgroundColor(android.R.color.background_light);
}
/////////////////////////////////////
holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
holder.txt_itemDescription.setText(itemDetailsrrayList.get(position).getItemDescription());
// holder.txt_itemPrice.setText(itemDetailsrrayList.get(position).getPrice());
holder.itemImage.setImageResource(imgid[itemDetailsrrayList.get(position).getImageNumber() - 1]);
return convertView;
}