--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/02/02 08:44:35 578 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/06/11 18:46:46 840 @@ -1,25 +1,33 @@ package dk.thoerup.traininfo; +import static dk.thoerup.traininfo.R.string.generic_cancel; +import static dk.thoerup.traininfo.R.string.generic_retry; +import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata; +import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror; +import static dk.thoerup.traininfo.R.string.timetablelist_nodata; + import java.util.ArrayList; import java.util.List; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.ListActivity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; +import android.view.View; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.provider.TimetableProvider; import dk.thoerup.traininfo.util.MessageBox; -import static dk.thoerup.traininfo.R.string.*; -public class TimetableList extends Activity { +public class TimetableList extends ListActivity { private static final int DLG_PROGRESS = 8000; DepartureBean departure; @@ -37,10 +45,9 @@ provider = ProviderFactory.getTimetableProvider(); - adapter = new TimetableListAdapter(this); - - ListView lv = (ListView) findViewById(R.id.List); - lv.setAdapter(adapter); + adapter = new TimetableListAdapter(this); + setListAdapter(adapter); + Intent launchedBy = getIntent(); @@ -61,7 +68,27 @@ } } - @Override + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + + TimetableBean tt = timetables.get(position); + + StationBean station = new StationBean(); + station.setName( tt.getStation() ); + station.setId( tt.getStationId() ); + station.setRegional(true); + + Intent intent = new Intent(this, DepartureList.class); + intent.putExtra("stationbean", station); + startActivity(intent); + + } + + + + @Override public void onSaveInstanceState(Bundle outState) { dismissDialog(DLG_PROGRESS); @@ -96,7 +123,7 @@ void startTimetableFetcher() { showDialog(DLG_PROGRESS); fetcher = new TimetableFetcher(); - fetcher.execute(departure.getTrainNumber()); + fetcher.execute(departure.getType(), departure.getTrainNumber()); } class TimetableFetcher extends AsyncTask { @@ -129,17 +156,24 @@ public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } - }); - builder.show(); + }); + + try { + builder.show(); + } catch (android.view.WindowManager.BadTokenException e) { + Log.i("TimetableList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running + } + } } @Override protected Void doInBackground(String... arg0) { - String trainID = arg0[0]; - success = provider.lookupTimetable(trainID); - timetables = provider.getTimetable(trainID); + String type = arg0[0]; + String trainID = arg0[1]; + success = provider.lookupTimetable(type, trainID); + timetables = provider.getTimetable(type, trainID); return null; }