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); int iconID; if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 || station.getNote().toLowerCase().indexOf("aflyst") > -1 ) { iconID = R.drawable.warn20; } else { iconID = R.drawable.info20; } image.setImageResource( iconID ); } ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); String trainNumber = station.getTrainNumber().trim(); String code = trainNumber.split(" ")[0]; if ( code.equalsIgnoreCase("ra")) { //ra = regionaltog arriva typeIcon.setImageResource(R.drawable.re); } else if ( code.equalsIgnoreCase("re")) { typeIcon.setImageResource(R.drawable.re); } else if ( code.equalsIgnoreCase("l")) { typeIcon.setImageResource(R.drawable.lyn); } else if ( code.equalsIgnoreCase("ic")) { typeIcon.setImageResource(R.drawable.ic); } else if ( code.equalsIgnoreCase("pp")) { typeIcon.setImageResource(R.drawable.pp); } else if ( code.equalsIgnoreCase("ør")) { typeIcon.setImageResource(R.drawable.or); } else if ( code.equalsIgnoreCase("a") ) { typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1 } else if ( code.equalsIgnoreCase("b") ) { typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52 } else if ( code.equalsIgnoreCase("bx") ) { typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d } else if ( code.equalsIgnoreCase("c") ) { typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734 } else if ( code.equalsIgnoreCase("e") ) { typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba } else if ( code.equalsIgnoreCase("f") ) { typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d } else if ( code.equalsIgnoreCase("h") ) { typeIcon.setImageResource(R.drawable.stog_h); //S-Tog:H banen #f05737 } else { typeIcon.setImageResource(R.drawable.unknown); } //Mangler: SJ=Sverige?, EC, return root; } }