14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: Intents, Broadcast Receivers, Adapters, and the Internet<br />

154<br />

public boolean onCreateOptionsMenu(Menu menu) {<br />

super.onCreateOptionsMenu(menu);<br />

}<br />

menu.add(0, MENU_UPDATE, Menu.NONE, R.string.menu_update);<br />

return true;<br />

@Override<br />

public boolean onOptionsItemSelected(MenuItem item) {<br />

super.onOptionsItemSelected(item);<br />

}<br />

switch (item.getItemId()) {<br />

case (MENU_UPDATE): {<br />

refreshEarthquakes();<br />

return true;<br />

}<br />

}<br />

return false;<br />

11. Now add some interaction. Let users fi nd more details by opening a Dialog box when they<br />

select an earthquake from the list.<br />

11.1. Creating a new quake_details.xml layout resource for the Dialog box you’ll display on<br />

an item click.<br />

<br />

<br />

<br />

<br />

11.2. Then modify your onCreate method to add an ItemClickListener to the List View<br />

that displays a Dialog box whenever an earthquake item is selected.<br />

static final private int QUAKE_DIALOG = 1;<br />

Quake selectedQuake;<br />

@Override<br />

public void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setContentView(R.layout.main);<br />

earthquakeListView =

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!