/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java
ViewVC logotype

Annotation of /android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1066 - (hide annotations) (download)
Thu Sep 16 15:32:42 2010 UTC (13 years, 8 months ago) by torben
File size: 1984 byte(s)
Experimental #5, update TrainInfo client to use common data-beans
1 torben 362 package dk.thoerup.traininfo;
2    
3     import android.content.Context;
4     import android.view.LayoutInflater;
5     import android.view.View;
6     import android.view.ViewGroup;
7     import android.widget.BaseAdapter;
8 torben 365 import android.widget.TextView;
9 torben 1066 import dk.thoerup.android.traininfo.common.TimetableBean;
10     import dk.thoerup.android.traininfo.common.TimetableEntry;
11 torben 362
12     public class TimetableListAdapter extends BaseAdapter {
13    
14 torben 1066 private TimetableBean timetable;
15 torben 362 LayoutInflater inflater;
16     Context context;
17    
18 torben 366 @Override
19     public boolean isEnabled(int position) {
20 torben 1066 return ( timetable.entries.get(position).getStationId() != -1 );
21 torben 366 }
22    
23 torben 362 public TimetableListAdapter(Context context) {
24     super();
25     this.context = context;
26    
27     inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
28     }
29    
30 torben 1066 public void setTimetable(TimetableBean timetable) {
31 torben 362 this.timetable = timetable;
32     notifyDataSetChanged();
33     }
34    
35     @Override
36     public int getCount() {
37     if (timetable != null)
38 torben 1066 return timetable.entries.size();
39 torben 362 else
40     return 0;
41     }
42    
43     @Override
44     public Object getItem(int position) {
45     return null;
46     }
47    
48     @Override
49     public long getItemId(int position) {
50     return position;
51     }
52    
53     @Override
54     public View getView(int position, View convertView, ViewGroup parent) {
55 torben 1066 TimetableEntry entry = timetable.entries.get(position);
56 torben 365
57 torben 491 View root = inflater.inflate(R.layout.timetablerow , parent, false);
58 torben 365
59     TextView station = (TextView) root.findViewById(R.id.Station);
60 torben 1066 station.setText(entry.getStation());
61 torben 365
62     TextView arrival = (TextView) root.findViewById(R.id.Arrival);
63 torben 1066 arrival.setText(entry.getArrival());
64 torben 365
65     TextView departure = (TextView) root.findViewById(R.id.Departure);
66 torben 1066 departure.setText(entry.getDeparture());
67 torben 365
68    
69 torben 1066 if (entry.isCurrent()) {
70 torben 365 final int bgcolor = 0xFFFFFFFF;
71     final int fgcolor = 0xFF000000;
72    
73     station.setTextColor(fgcolor);
74     arrival.setTextColor(fgcolor);
75     departure.setTextColor(fgcolor);
76     root.setBackgroundColor(bgcolor);
77     }
78    
79     return root;
80 torben 362 }
81    
82     }

  ViewVC Help
Powered by ViewVC 1.1.20