package dk.thoerup.traininfo; import java.text.NumberFormat; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class StationListAdapter extends BaseAdapter { LayoutInflater inflater; List stations; Context context; NumberFormat number = NumberFormat.getNumberInstance(); public StationListAdapter(Context context) { super(); this.context = context; inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); number.setMaximumFractionDigits(1); number.setMinimumFractionDigits(1); } @Override public int getCount() { if (stations != null) return stations.size(); else return 0; } @Override public Object getItem(int position) { return null; } public StationBean getStation(int position) { return stations.get(position); } @Override public long getItemId(int position) { return position; } public void setStations(List stations) { this.stations = stations; notifyDataSetChanged(); } @Override public View getView(int position, View convertView, ViewGroup parent) { StationBean station = stations.get(position); View root = inflater.inflate(R.layout.stationrow , parent, false); TextView tview = (TextView) root.findViewById(R.id.stationName); tview.setText(station.getName()); tview = (TextView) root.findViewById(R.id.stationDistance); tview.setText("Distance: " + number.format( (double)station.getDistance()/1000.0) + " km."); root.findViewById(R.id.isregional).setVisibility( station.isRegional() ? View.VISIBLE : View.INVISIBLE ); root.findViewById(R.id.isstrain).setVisibility( station.isSTrain() ? View.VISIBLE : View.INVISIBLE ); root.findViewById(R.id.ismetro).setVisibility( station.isMetro() ? View.VISIBLE : View.INVISIBLE ); return root; } }