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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Peer-to-Peer Communication<br />

300<br />

5. At this point, the GUI will be complete, so starting the application should show you the screen<br />

shown in Figure 9-3.<br />

Figure 9-3<br />

6. Create a new Array List of Strings within the EmergencyResponder Activity to store the phone<br />

numbers of the incoming requests for your status. Bind the Array List to the List View, using an<br />

Array Adapter in the Activity’s onCreate method, and create a new ReentrantLock object to<br />

ensure thread safe handling of the Array List.<br />

Take the opportunity to get a reference to the Check Box and to add Click Listeners for each<br />

of the response buttons. Each button should call the respond method, while the Setup Auto<br />

Responder button should call the startAutoResponder stub.<br />

ReentrantLock lock;<br />

CheckBox locationCheckBox;<br />

ArrayList requesters;<br />

ArrayAdapter aa;<br />

@Override<br />

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

super.onCreate(icicle);<br />

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

}<br />

lock = new ReentrantLock();<br />

requesters = new ArrayList();<br />

wireUpControls();<br />

private void wireUpControls() {<br />

locationCheckBox = (CheckBox)findViewById(R.id.checkboxSendLocation);

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

Saved successfully!

Ooh no, something went wrong!