/*
* Copyright 2011 Giles Malet.
*
* This file is part of GRTransit.
*
* GRTransit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRTransit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRTransit. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* An adapter that is used when drawing the main window list of details.
*/
package com.wbrenna.gtfsoffline;
import java.util.ArrayList;
import android.app.ListActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ListArrayAdapter extends ArrayAdapter <String[]> {
// private static final String TAG = "ListArrayAdapter";
private final ArrayList<String[]> mDetails;
private final LayoutInflater mInflater;
private final int mLayout;
private boolean ampmflag;
public ListArrayAdapter(ListActivity context, int layout, boolean ampm, ArrayList<String[]> details) {
super(context, layout, details);
// Log.v(TAG, "TimesArrayAdapter()");
mDetails = details;
mInflater = LayoutInflater.from(context);
mLayout = layout;
ampmflag = ampm;
}
static class ViewHolder {
TextView stoptime;
TextView desc;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder;
// Reuse the convertView if we already have one.... Android will create
// only enough to fill the screen.
if (view == null) {
view = mInflater.inflate(mLayout, parent, false);
// Save the view when we look them up.
holder = new ViewHolder();
holder.stoptime = (TextView) view.findViewById(R.id.stoptime);
holder.desc = (TextView) view.findViewById(R.id.desc);
view.setTag(holder);
} else {
// Log.d(TAG, "reusing view " + view);
holder = (ViewHolder) view.getTag();
}
holder.stoptime.setText(ServiceCalendar.formattedTime(mDetails.get(position)[0],ampmflag));
holder.desc.setText(mDetails.get(position)[1]);
return view;
}
}