package dk.thoerup.traininfo; import java.util.List; 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; public class DepartureListAdapter extends BaseAdapter { private List departures; LayoutInflater inflater; Context context; public DepartureListAdapter(Context context) { super(); this.context = context; inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setDepartures(List departures) { this.departures = departures; notifyDataSetChanged(); } @Override public int getCount() { if (departures != null) return departures.size(); else return 0; } public DepartureBean getDeparture(int position) { return departures.get(position); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { DepartureBean station = departures.get(position); View root = inflater.inflate(R.layout.departurerow , parent, false); ((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); if (station.getStatus().length() > 0 || station.getNote().length() > 0) { ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); image.setImageResource(R.drawable.info20); } ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); String trainNumber = station.getTrainNumber(); if (trainNumber.length() >= 2) { if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva typeIcon.setImageResource(R.drawable.retog); } else if ( trainNumber.substring(0, 2).equalsIgnoreCase("re")) { typeIcon.setImageResource(R.drawable.retog); } else if (trainNumber.substring(0,1).equalsIgnoreCase("l")) { typeIcon.setImageResource(R.drawable.lyntog); } else if (trainNumber.substring(0,2).equalsIgnoreCase("ic")) { typeIcon.setImageResource(R.drawable.ictog); } else if (trainNumber.substring(0,2).equalsIgnoreCase("pp")) { typeIcon.setImageResource(R.drawable.pptog); } } else { //if each line needs seperate icons, switch on the first(and only( character typeIcon.setImageResource(R.drawable.stog); } return root; } }