Return trueIntent extra C


intent = new Intent(this, ReviewCriteria.class); startActivity(intent); return true;

Override onListItemClick return super.onMenuItemSelected(featureld, item);

@Override protected void onListItemClick(ListView l, View v, D

RestaurantFinderApplication application =

(RestaurantFinderApplication) getApplication(); application.setCurrentReview( );

Intent intent = new Intent (Constants . INTENT_ACTION_VIEW_DETAIL); intent.putExtra(Constants.STARTFROM_EXTRA, getIntent().getIntExtra(

Constants . STARTFROM_EXTRA, 1)); <1 startActivity (intent) ; | Pass startFrom Get Application

} © extra value object and set state E

private void loadReviews(String location, String cuisine, int startFrom) { <1-1 „ . . ,„ .

| Create loadReviews final ReviewFetcher rf = new ReviewFetcher (location, method cuisine, "ALL", startFrom,

ReviewList .NUM_RESULTS_PER_PAGE) ; <-1 Instantiate

I ReviewFetcher © instance this.progressDialog =, " Working...'

reviews = rf.getReviews ();

Show ProgressDialog

¿Make web service call

} 1) Update handler

This Activity has a menu item that allows the user to get the next page of results or change the list criteria. To support this we have to implement the onMenuItemSelected method Q. If the MENU_GET_NEXT_PAGE menu item is selected, we then define a new intent to reload the screen with an incremented startFrom value (and we use the getExtras() and putExtras() intent methods to do this) ©.

After the menu-related methods, we see a special onListItemClick() method ©. This method is used to respond when one of the list items in a ListView is clicked. Here we use the position of the clicked item to reference the particular Review item the user chose, and we set this into the Application for later usage in the ReviewDetail Activity (which we will begin to implement in section 3.3) ©. After we have the data set, we then call the next Activity (including the startFrom extra) ©.

Lastly in the ReviewList class we have the loadReviews() method, which, strangely enough, loads reviews ©. This method is significant for several reasons. First it sets up the ReviewFetcher class instance, which will be used to call out to the Google Base API over the network and return a List of Review objects © (again, networking details are in chapter 6). Then it invokes the method to show the user we are retrieving data ©. Finally it sets up a new Thread ©, within which the ReviewFetcher is used, and the earlier Handler we saw in the first half of ReviewList is sent an empty message 1). If you refer back to when the Handler was established, in listing 3.3, you can see that is where, when the message is received, we dismiss the ProgressDialog, populate the Adapter our ListView is using, and call setListAdapter() to update the UI. The setListAdapter() method will iterate the Adapter it is handed and display a returned View for every item.

With the Activity created and set up and the Handler being used to update the Adapter with data, we now have a second screen in our application. The next thing we need to do is fill in some of the gaps surrounding working with handlers and different threads. These concepts are not view-specific but are worth a small detour at this point because you will want to use these classes when trying to perform tasks related to retrieving and manipulating data needed for the UI.

0 0

Post a comment