- Understanding the Java WTK
- The RTTTLEx Application
- Creating a List of Ring Tones
- Understanding the MIDP List Class
- Working with the Display Object and the Displayable Interface
- Configuring Commands
- Registering CommandListeners
- The Methods of a MIDlet
- Selecting a Tune
- The MIDP Canvas Object
- Playing a Tune
- Conclusion
Understanding the MIDP List Class
The MIDP List class enables a list of strings to appear on a mobile device's screen. The List class also allows commands to be triggered when a user clicks an item in the list. You can conceptualize a MIDP List as an HTML <SELECT> element for the cell phone screen. A <SELECT> element on a web page can offer users the ability to select one item or multiple items; the user has the same capability with the MIDP List class. I use the append() method of the List class to add the captions stored in the mcaptions array. Listing 2 shows how the RTTTLEx application creates the MIDP List:
Listing 2 Populating an MIDP List Object
//Create a new List object theList = new List("RTTTLEx Ring Tones", Choice.IMPLICIT); //Traverse the captions array and add the array's contents //to the list. for (int i = 0; i < mcaptions.length; i++) { theList.append(mcaptions[i], null); }
Notice the constructor for the List object:
theList = new List("RTTTLEx Ring Tones", Choice.IMPLICIT);
The first parameter of the constructor gives the list a title, which will eventually be displayed on the screen title portion of the mobile device. In this case, the title is "RTTTLEx Ring Tones," as shown in Figure 3. The second parameter defines the Choice type. This parameter can have one of three values:
Choice.EXCLUSIVE tells the application to display the list so that only one choice can be made a time.
Choice.MULTIPLE allows the user to select multiple values from the list.
Choice.IMPLICIT makes the list item subject to the command invoked on it when the user selects one of the command keys in the mobile device. In this case, as shown in Figure 3, the available commands are Exit and Play.
Figure 3 Setting the title of a List object.
TIP
The Choice.EXCLUSIVE and Choice.MULTIPLE configuration settings are very much like those used to configure an HTML <SELECT> element.