1 |
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 |
import android.widget.TextView;
|
11 |
|
12 |
public class DepartureListAdapter extends BaseAdapter {
|
13 |
|
14 |
private List<DepartureBean> departures;
|
15 |
LayoutInflater inflater;
|
16 |
Context context;
|
17 |
public DepartureListAdapter(Context context) {
|
18 |
super();
|
19 |
this.context = context;
|
20 |
|
21 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
22 |
}
|
23 |
|
24 |
public void setDepartures(List<DepartureBean> departures) {
|
25 |
this.departures = departures;
|
26 |
notifyDataSetChanged();
|
27 |
}
|
28 |
|
29 |
@Override
|
30 |
public int getCount() {
|
31 |
if (departures != null)
|
32 |
return departures.size();
|
33 |
else
|
34 |
return 0;
|
35 |
}
|
36 |
|
37 |
public DepartureBean getDeparture(int position) {
|
38 |
return departures.get(position);
|
39 |
}
|
40 |
|
41 |
@Override
|
42 |
public Object getItem(int position) {
|
43 |
return null;
|
44 |
}
|
45 |
|
46 |
@Override
|
47 |
public long getItemId(int position) {
|
48 |
return position;
|
49 |
}
|
50 |
|
51 |
@Override
|
52 |
public View getView(int position, View convertView, ViewGroup parent) {
|
53 |
DepartureBean station = departures.get(position);
|
54 |
|
55 |
View root = inflater.inflate(R.layout.departurerow , parent, false);
|
56 |
|
57 |
((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
|
58 |
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
|
59 |
|
60 |
|
61 |
return root;
|
62 |
}
|
63 |
|
64 |
}
|