1 |
torben |
362 |
package dk.thoerup.traininfo; |
2 |
|
|
|
3 |
|
|
import java.util.List; |
4 |
|
|
|
5 |
|
|
import android.content.Context; |
6 |
torben |
490 |
import android.util.Log; |
7 |
torben |
362 |
import android.view.LayoutInflater; |
8 |
|
|
import android.view.View; |
9 |
|
|
import android.view.ViewGroup; |
10 |
|
|
import android.widget.BaseAdapter; |
11 |
torben |
365 |
import android.widget.TextView; |
12 |
torben |
362 |
|
13 |
|
|
public class TimetableListAdapter extends BaseAdapter { |
14 |
|
|
|
15 |
|
|
private List<TimetableBean> timetable; |
16 |
|
|
LayoutInflater inflater; |
17 |
|
|
Context context; |
18 |
|
|
|
19 |
torben |
366 |
@Override |
20 |
|
|
public boolean isEnabled(int position) { |
21 |
|
|
return false; |
22 |
|
|
} |
23 |
|
|
|
24 |
torben |
362 |
public TimetableListAdapter(Context context) { |
25 |
|
|
super(); |
26 |
|
|
this.context = context; |
27 |
|
|
|
28 |
|
|
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
public void setTimetable(List<TimetableBean> timetable) { |
32 |
|
|
this.timetable = timetable; |
33 |
|
|
notifyDataSetChanged(); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
@Override |
37 |
|
|
public int getCount() { |
38 |
|
|
if (timetable != null) |
39 |
|
|
return timetable.size(); |
40 |
|
|
else |
41 |
|
|
return 0; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
@Override |
45 |
|
|
public Object getItem(int position) { |
46 |
|
|
return null; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
@Override |
50 |
|
|
public long getItemId(int position) { |
51 |
|
|
return position; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
@Override |
55 |
|
|
public View getView(int position, View convertView, ViewGroup parent) { |
56 |
torben |
365 |
TimetableBean timetableBean = timetable.get(position); |
57 |
|
|
|
58 |
torben |
490 |
View root; |
59 |
|
|
if (convertView == null || convertView.getId() != R.id.TimetableRow) { |
60 |
|
|
root = inflater.inflate(R.layout.timetablerow , parent, false); |
61 |
|
|
} else { |
62 |
|
|
root = convertView; |
63 |
|
|
} |
64 |
torben |
365 |
|
65 |
|
|
TextView station = (TextView) root.findViewById(R.id.Station); |
66 |
|
|
station.setText(timetableBean.getStation()); |
67 |
|
|
|
68 |
|
|
TextView arrival = (TextView) root.findViewById(R.id.Arrival); |
69 |
|
|
arrival.setText(timetableBean.getArrival()); |
70 |
|
|
|
71 |
|
|
TextView departure = (TextView) root.findViewById(R.id.Departure); |
72 |
|
|
departure.setText(timetableBean.getDeparture()); |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
if (timetableBean.isCurrent()) { |
76 |
|
|
final int bgcolor = 0xFFFFFFFF; |
77 |
|
|
final int fgcolor = 0xFF000000; |
78 |
|
|
|
79 |
|
|
station.setTextColor(fgcolor); |
80 |
|
|
arrival.setTextColor(fgcolor); |
81 |
|
|
departure.setTextColor(fgcolor); |
82 |
|
|
root.setBackgroundColor(bgcolor); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
return root; |
86 |
torben |
362 |
} |
87 |
|
|
|
88 |
|
|
} |