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