4 |
import java.util.List; |
import java.util.List; |
5 |
|
|
6 |
import android.content.Context; |
import android.content.Context; |
|
import android.util.Log; |
|
7 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
8 |
import android.view.View; |
import android.view.View; |
9 |
import android.view.ViewGroup; |
import android.view.ViewGroup; |
10 |
import android.widget.BaseAdapter; |
import android.widget.BaseAdapter; |
11 |
import android.widget.TextView; |
import android.widget.TextView; |
12 |
|
import static dk.thoerup.traininfo.R.string.*; |
13 |
|
|
14 |
public class StationListAdapter extends BaseAdapter { |
public class StationListAdapter extends BaseAdapter { |
15 |
LayoutInflater inflater; |
LayoutInflater inflater; |
58 |
public View getView(int position, View convertView, ViewGroup parent) { |
public View getView(int position, View convertView, ViewGroup parent) { |
59 |
StationBean station = stations.get(position); |
StationBean station = stations.get(position); |
60 |
|
|
61 |
View root; |
View root = inflater.inflate(R.layout.stationrow , parent, false); |
|
if (convertView == null || convertView.getId() != R.id.StationRow) { |
|
|
root = inflater.inflate(R.layout.stationrow , parent, false); |
|
|
} else { |
|
|
root = convertView; |
|
|
} |
|
|
|
|
62 |
TextView tview = (TextView) root.findViewById(R.id.stationName); |
TextView tview = (TextView) root.findViewById(R.id.stationName); |
63 |
tview.setText(station.getName()); |
tview.setText(station.getName()); |
64 |
|
|
65 |
tview = (TextView) root.findViewById(R.id.stationDistance); |
tview = (TextView) root.findViewById(R.id.stationDistance); |
66 |
tview.setText("Distance: " + number.format( (double)station.getDistance()/1000.0) + " km."); |
if (station.getDistance() != 0) { |
67 |
|
tview.setText( context.getString(stationlistadapter_distance) + " " + number.format( (double)station.getDistance()/1000.0) + " km."); |
68 |
|
} else { |
69 |
|
tview.setVisibility(View.INVISIBLE); |
70 |
|
} |
71 |
|
|
72 |
|
root.findViewById(R.id.isregional).setVisibility( station.isRegional() ? View.VISIBLE : View.INVISIBLE ); |
73 |
|
root.findViewById(R.id.isstrain).setVisibility( station.isSTrain() ? View.VISIBLE : View.INVISIBLE ); |
74 |
|
root.findViewById(R.id.ismetro).setVisibility( station.isMetro() ? View.VISIBLE : View.INVISIBLE ); |
75 |
|
|
76 |
return root; |
return root; |
77 |
} |
} |