Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Hãy nhớ rằng, các yếu tố được đưa vào một danh sách trước khi các yếu tố quy định. Nếu một danh sách có 3 yếu tố như hình dưới đây và một phần tử ("Z") được đưa vào bằng cách xác định một chỉ số chèn 2, yếu tố mới sẽ được đưa vào trước khi vào phần tử 2, như hình dưới đây. | Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com will change. Remember elements are inserted into a list prior to the element specified. If a list has 3 elements as shown below and an element Z is inserted by specifying an insert index of 2 the new element will be inserted prior to element 2 as shown below. The element inserted will have the index 2 and the element previously at position 2 will now have an index of 3. somelist.insert 2 Z null Before Insertion Elements A B C Index 0 1 2 After Insertion Elements A B Z C Index 0 1 2 3 Before leaving this example take a minute to look over the code in commandAction . Notice the check to see if the Command that initiated the event was an implicit List. Also look at the switch statement that uses lsDocument.getSelectedIndex to determine which element was selected and print a message to the console. public void commandAction Command c Displayable s if c List.SELECT_COMMAND switch lsDocument.getSelectedIndex case 0 System.out.println Next break . . Example Multiple Choice List Changing our List from implicit to multiple choice is a piece of cake. All that changes is the declaration of the List. Implicit lsDocument new List Document Option List.IMPLICIT options images Multiple Choice lsDocument new List Document Option List.MULTIPLE options images 155 Simpo PDF Merge and Split Unregistered Version - http www.simpopdf.com The last List example will create a multiple choice list and fill an array of boolean values with the selection status of each entry. The MIDlet and console output shown when the View option is selected are shown in Figure 8-6. Figure 8-6. Multiple Choice List Example 8.2 MultipleChoiceList.java --------------------------------------------------- MultipleChoiceList.java Create multiple choice list and save selection status of each element in an array. ------------------------------------------------- import javax.microedition.midlet. import javax.microedition.lcdui. public class .