package dk.thoerup.traininfo; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import dk.thoerup.android.traininfo.common.TimetableBean; import dk.thoerup.android.traininfo.common.TimetableEntry; public class TimetableListAdapter extends BaseAdapter { private TimetableBean timetable; LayoutInflater inflater; Context context; @Override public boolean isEnabled(int position) { return ( timetable.entries.get(position).getStationId() != -1 ); } public TimetableListAdapter(Context context) { super(); this.context = context; inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setTimetable(TimetableBean timetable) { this.timetable = timetable; notifyDataSetChanged(); } @Override public int getCount() { if (timetable != null) return timetable.entries.size(); else return 0; } @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) { TimetableEntry entry = timetable.entries.get(position); View root = inflater.inflate(R.layout.timetablerow , parent, false); TextView station = (TextView) root.findViewById(R.id.Station); station.setText(entry.getStation()); TextView arrival = (TextView) root.findViewById(R.id.Arrival); arrival.setText(entry.getArrival()); TextView departure = (TextView) root.findViewById(R.id.Departure); departure.setText(entry.getDeparture()); if (entry.isCurrent()) { final int bgcolor = 0xFFFFFFFF; final int fgcolor = 0xFF000000; station.setTextColor(fgcolor); arrival.setTextColor(fgcolor); departure.setTextColor(fgcolor); root.setBackgroundColor(bgcolor); } return root; } }