--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/05/03 11:19:18 699 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/06/26 11:02:53 918 @@ -10,22 +10,24 @@ 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; -public class TimetableList extends Activity { +public class TimetableList extends ListActivity { private static final int DLG_PROGRESS = 8000; DepartureBean departure; @@ -43,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(); @@ -66,8 +67,36 @@ adapter.setTimetable(timetables); } } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (fetcher != null) { + fetcher.cancel(true); + } + } - @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); @@ -116,9 +145,10 @@ if (success) { + TimetableList.this.getListView().invalidateViews(); adapter.setTimetable(timetables); if (timetables.size() == 0) { - MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata)); + MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); } } else { // communication or parse error AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); @@ -134,6 +164,7 @@ builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); + TimetableList.this.finish(); } });