Last active
August 29, 2015 14:04
-
-
Save aows/c70a80d2449924d64c93 to your computer and use it in GitHub Desktop.
Example activity using Trimet Services library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
private ListView mListView; | |
private ArrayAdapter<String> mAdapter; | |
private Button mButton; | |
private ProgressDialog mPD; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// init trimet services | |
TrimetServices.init(this); | |
// register activity | |
TrimetRouteConfig.get().register(this); | |
// show loading dialog | |
mPD = new ProgressDialog(this); | |
mPD.setMessage(getResources().getString(R.string.loading)); | |
mPD.setIndeterminate(true); | |
mPD.setCancelable(false); | |
mListView = (ListView) findViewById(R.id.list); | |
mAdapter = new ArrayAdapter<String>(this, R.layout.list_row); | |
mListView.setAdapter(mAdapter); | |
mButton = (Button) findViewById(R.id.button); | |
mButton.setOnClickListener(new View.OnClickListener() { | |
@Override public void onClick(View v) { | |
mPD.show(); | |
TrimetRouteConfig.get().getAllRoutes(); | |
} | |
}); | |
} | |
@Override | |
protected void onDestroy() { | |
// unregister the activity as a subscriber | |
TrimetRouteConfig.get().unregister(this); | |
super.onDestroy(); | |
} | |
@Subscribe | |
public void onLinesAvailable(RouteConfigResult result) { | |
mPD.hide(); | |
for (PBRoute pbRoute : result.getRoutes()) { | |
mAdapter.add(pbRoute.getDescription()); | |
} | |
mAdapter.notifyDataSetChanged(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment