Listening for Selection Events

You want to save the Spinner control option chosen as soon as the user selects one. To do this, you use the setOnItemSelectedListener() method of the Spinner control to listen for selection events. Specifically, you need to implement the onItemSelected() method of AdapterView.OnItemSelectedListener, like this:

spinner.setOnItemSelectedListener(

new AdapterView.OnItemSelectedListener() { ©Override public void onItemSelected(AdapterView<?> parent, View itemSelected, int selectedItemPosition, long selectedId) {

// TODO: Save item index (selectedItemPosition) as Gender setting

// ... Other required overrides

ByWay

With certain versions of the Android SDK, you might also need to provide the appropriate stub implementations for other required methods of the AdapterView.OnItemSelectedListener class.

At this point, save the QuizSettingsActivity.java file and run the Been There, Done That! application in the Android emulator. After the splash screen finishes, choose the settings screen option. The screen should look as shown in Figure 10.8.

FIGURE 10.8

The Been There, Done That! settings screen.

0 0

Post a comment