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