|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-462239D1-4B40-4342-92DA-32AB0AF0D2F2" xml:lang="en"><title>Creating |
|
13 the choice list</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>To use a choice list in your application, create an instance of the class <codeph>CAknChoiceList</codeph>. </p> |
|
15 <p>Use the <codeph>CAknChoiceList::NewL</codeph> parameters to set the style |
|
16 of the choice list.</p> |
|
17 <p>If you give no parameters, the defaults will be used. With the default |
|
18 parameters, a choice list with current selection is constructed.</p> |
|
19 <p>To construct a choice list without a current selection, use the flag <codeph>CAknChoiceList::EaknChoiceListWithoutCurrentSelection</codeph> and |
|
20 an instance of <codeph>CaknButton</codeph> in the constructor. This button |
|
21 will be then used to open the choice list. The ownership of the button is |
|
22 transferred to the choice list.</p> |
|
23 <p>The following sample code illustrates creating a default choice list.</p> |
|
24 <codeblock xml:space="preserve">const TInt KArrayGranularity ( 1 ); |
|
25 |
|
26 // Create array of choice list items |
|
27 CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat ( KArrayGranularity ); |
|
28 CleanupStack::PushL( array ); |
|
29 |
|
30 _LIT( KListItem, "Item %d" ); |
|
31 |
|
32 for ( TInt k = 0; k < 5; k++ ) |
|
33 { |
|
34 TBuf<32> buf; |
|
35 buf.Format( KListItem, k ); |
|
36 array->AppendL( buf ); |
|
37 } |
|
38 |
|
39 // Create choice list with array |
|
40 iChoiceList = CAknChoiceList::NewL( this, array ); |
|
41 |
|
42 CleanupStack::Pop( array ); |
|
43 |
|
44 iChoiceList->SetObserver( this ); |
|
45 </codeblock> |
|
46 <p>The following sample code illustrates creating a button choice list with |
|
47 items from resources:</p> |
|
48 <codeblock xml:space="preserve"> _LIT( KButtonTxt, "Choice list" ); |
|
49 _LIT( KButtonHelpTxt, "Button help text" ); |
|
50 |
|
51 // Create a button for the choice list |
|
52 CAknButton* button = CAknButton::NewLC( NULL, |
|
53 NULL, |
|
54 NULL, |
|
55 NULL, |
|
56 KButtonTxt, |
|
57 KButtonHelpTxt, |
|
58 KAknButtonSizeFitText, |
|
59 0 ); |
|
60 |
|
61 // Create empty Choice list |
|
62 iChoiceList = CAknChoiceList::NewL( this, NULL, |
|
63 CAknChoiceList::EAknChoiceListWithoutCurrentSelection, button ); |
|
64 CleanupStack::Pop( button ); |
|
65 |
|
66 // Add items from resource |
|
67 iChoiceList->SetItemsL( R_CHOICELISTEX_ITEM_ARRAY ); |
|
68 iArraySize = ArraySizeL( R_CHOICELISTEX_ITEM_ARRAY ); |
|
69 iSelection = 0; |
|
70 |
|
71 iChoiceList->SetObserver( this ); |
|
72 </codeblock> |
|
73 </conbody></concept> |