March 2013
Beginner to intermediate
580 pages
16h 11m
English
In this chapter, you did not need a result back from the started activity. What if you did? Your code would look a lot like it did in GeoQuiz. Instead of using the Activity’s startActivityForResult(…) method, you would use Fragment.startActivityForResult(…). Instead of overriding Activity.onActivityResult(…), you would override Fragment.onActivityResult(…).
public class CrimeListFragment extends ListFragment { private static final int REQUEST_CRIME = 1; ... public void onListItemClick(ListView l, View v, int position, long id) { // Get the Crime from the adapter Crime c = ((CrimeAdapter)getListAdapter()).getItem(position); Log.d(TAG, c.getTitle() + " was clicked"); // Start CrimeActivity Intent i = new Intent(getActivity(), ...Read now
Unlock full access