私のアプリケーションでは、ユーザーが家庭用製品を注文し、アプリケーションがリストビューに製品名と価格を表示します。在庫切れの製品に異なる背景を設定したいと思います。誰かが私を助けることができますか?
パブリッククラスProductsはBaseAdapterを拡張します{
public ArrayList<HashMap<String, String>> list;
Activity activity;
boolean Connection;
public Products(Activity activity,
ArrayList<HashMap<String, String>> list) {
super();
this.activity = activity;
this.list = list;
}
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
class ViewHolder {
TextView item_name,item_price,product_id,item_stock;
}
public View getView(final int position, View convertView,
final ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.submenutext, null);
if(ITEM_AVALIABLE_QUANTITY.equalsIgnoreCase("0")){
convertView.setBackgroundResource(R.drawable.heading);
}
/*else{
convertView.setBackgroundResource(R.drawable.sub_menu);
}*/
holder = new ViewHolder();
holder.product_id = (TextView) convertView.findViewById(R.id.hide_text);
holder.item_name = (TextView) convertView.findViewById(R.id.text);
holder.item_price = (TextView) convertView.findViewById(R.id.price);
//holder.item_stock = (TextView)convertView.findViewById(R.id.stock);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final HashMap<String, String> map = list.get(position);
holder.product_id.setText(map.get(PRODUCT_ID));
holder.item_name.setText(map.get(ITEM_NAME_COLUMN));
holder.item_price.setText(map.get(ITEM_PRICE_COLUMN));
holder.item_stock.setText(map.get(ITEM_AVALIABLE_QUANTITY));
/*if(holder.item_stock.equals("0")){
convertView.setBackgroundResource(R.drawable.heading);
}*/
return convertView;
}
}