/[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 840 - (hide annotations) (download)
Fri Jun 11 18:46:46 2010 UTC (13 years, 11 months ago) by torben
File size: 1918 byte(s)
Enable forward navigation from timetable list to a new departure list
1 torben 362 package dk.thoerup.traininfo;
2    
3     import java.util.List;
4    
5     import android.content.Context;
6     import android.view.LayoutInflater;
7     import android.view.View;
8     import android.view.ViewGroup;
9     import android.widget.BaseAdapter;
10 torben 365 import android.widget.TextView;
11 torben 362
12     public class TimetableListAdapter extends BaseAdapter {
13    
14     private List<TimetableBean> timetable;
15     LayoutInflater inflater;
16     Context context;
17    
18 torben 366 @Override
19     public boolean isEnabled(int position) {
20 torben 840 return ( timetable.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     public void setTimetable(List<TimetableBean> timetable) {
31     this.timetable = timetable;
32     notifyDataSetChanged();
33     }
34    
35     @Override
36     public int getCount() {
37     if (timetable != null)
38     return timetable.size();
39     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 365 TimetableBean timetableBean = timetable.get(position);
56    
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     station.setText(timetableBean.getStation());
61    
62     TextView arrival = (TextView) root.findViewById(R.id.Arrival);
63     arrival.setText(timetableBean.getArrival());
64    
65     TextView departure = (TextView) root.findViewById(R.id.Departure);
66     departure.setText(timetableBean.getDeparture());
67    
68    
69     if (timetableBean.isCurrent()) {
70     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