package cz.netbox.mojekonto;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.List;
public class ContractListAdapter extends BaseAdapter {
private static final String TAG = "MojeKonto|ContractListAdapter";
private Context context;
private List<Contract> contracts;
private LayoutInflater mInflater;
public ContractListAdapter(Context context, List<Contract> contracts) {
this.context = context;
this.contracts = contracts;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return this.contracts.size();
}
public Contract getItem(int i) {
return this.contracts.get(i);
}
public long getItemId(int i) {
return ((Contract) this.contracts.get(i)).contractId;
}
public View getView(int i, View convertView, ViewGroup parent) {
SimpleDateFormat sdf = new SimpleDateFormat("d. M. yyyy");
Integer categoryId;
ContractViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.contract_choose_item, parent, false);
holder = new ContractViewHolder();
holder.serviceLabel = (TextView) convertView.findViewById(R.id.serviceLabel);
holder.contractNum = (TextView) convertView.findViewById(R.id.contractNum);
holder.sealed = (TextView) convertView.findViewById(R.id.sealed);
holder.category = (ImageView) convertView.findViewById(R.id.category);
convertView.setTag(holder);
} else {
holder = (ContractViewHolder) convertView.getTag();
}
holder.serviceLabel.setText(((Contract) this.contracts.get(i)).serviceLabel);
holder.contractNum.setText(((Contract) this.contracts.get(i)).contractNum);
holder.sealed.setText(sdf.format(((Contract) this.contracts.get(i)).sealed));
categoryId = ((Contract) this.contracts.get(i)).categoryId;
switch (categoryId) {
case 2: { // Tv
holder.category.setImageResource(R.drawable.list_tv);
} break;
case 3: { // Internet
holder.category.setImageResource(R.drawable.list_internet);
} break;
case 4: { // Balicek
holder.category.setImageResource(R.drawable.list_pack);
} break;
case 5: {
holder.category.setImageResource(R.drawable.list_tvpc);
} break;
}
return convertView;
}
}
class ContractViewHolder {
TextView serviceLabel;
TextView contractNum;
TextView sealed;
ImageView category;
}
|