Creating a CAknSettingItemList in a Dialog

Platforms:
Keywords:

Introduction

One of the more interesting classes in Avkon or Nokia Series 60 devices is the CAknSettingItemList control.

This control differs from the other list type controls in that it allows items to be edited and displayed in the list. The control will allow you to create a list of items with a wide range of editors.

Whilst there are a number of really good examples on this control and Nokia recently produced a document on this control , there is no clean explanation of how to use this control in a dialog.

In fact the solution provided can be used for most controls as there is a standard pattern for adding a custom control to a dialog in Symbian OS.

Creating the resources

The resources are definitely the most complex part of the operation. Anything wrong here and the dialog will just crash when it is being created.

In the SLIDlg.rss file, locate the string "Article Code from here onward". This is the point at which the new code for the settings dialog has been placed. First a dialog resource is defined. The only things that is important to note here is that the R_AVKON_SOFTKEYS_SELECT_CANCEL is used instead of the normal Ok/Cancel combination. This is very important as will be seen in the dialog section further on in the article.

The next thing that is required is the dialog line. For this, the "type" is set to a custom control type, in this case EAknCtLastControlId as this will not be confused with other intrinsic types, this value or any value higher can be used. (See Avkon.hrh for further details). What we are saying to the Avkon dialog manager is that we are using a custom control in the dialog and to handle it differently to other control. Specifically calling the functions CreateCustomControlL() and ConvertCustomControlTypeToBaseControlType(). Next the "id" of the control is created. In this case anything can be used as there will only be one control in the dialog, though the id must be unique in Series 60.

Finally the resource definition of the control need to be specified. As this control is a very simple settings editor it can be AVKON_SETTING_ITEM_LIST data type. Note however that each AVKON_SETTING_ITEM in the list is composed of three parts. This item itself , a page for the setting caption and value, and an editor.

Now examine the rss file. All the important items have been highlighted with comments starting with "// ****".

Creating the CAknSettingItemList

In order to use the CAknSettingItemList class and to provide editing functionality you will need to derive a class from CAknSettingItemList and then override the CreateSettingItemL() function to provide the relevant editors for each item in the settings list.

For the purposes of this sample we have just stored the data with the derived settings list item. In practise you will need to handle this by passing in your own structure with the data that is to be modified.

Now we have the setting item list we can go ahead and link it to the dialog. As an aside, the document on the Nokia web site has information on how to create new setting item editors.

Creating the dialog

Now we have a CAknSettingItemList we can create the dialog which will instantiate this list from the resources. Once the list is instantiated, the CreateSettingItemL() will be called to create all the components of the settings list.

Internally when the dialog is created using new, the resources will be read by the dialog manager. When it finds a custom control type (In this case CAknCtLastControlId) it will call the CreateCustomControlL() function which will allow the settings dialog class to create an instance of the setting item list.

Once this instance is created the dialog manager will then load the resources associated with the control. The final stage is to set the ConvertCustomControlTypeToBaseControlType() to tell the dialog manager that this control behaves like a popfield type control. The dialog manager uses this to decide how to route events and display the item in a dialog line.

At this stage you should be able to run the sample and have your settings displayed in a dialog box, you should also be able to navigate between the items, but not edit them.

Editing items

After the dialog box resources have been loaded, the settings item list will call CreateSettingItemL() to allow the creation of the controls each of the setting list items.

This will also associate your variables with the control. If your data is not ready at this point then you can set the data in the PostLayoutDynInitL() method of the dialog and call LoadSettingsL() on the item list control object.

This will then tell the settings item list to reload the data for the settings items To edit a settings item we override the OkToExitL() function so that when the user clicks the Select softkey it will edit the control in an item settings editor. You can change the parameter for the EditL() function to edit in place if you prefer.

Finally to save changes, the StoreSettingsL() function should be called which will copy all the data from the editors into your dialog data. Failing to call the StoreSettingsL() will not save the data into the variables.

Download

slidlg.zip
slidlg.zip

Conclusion

Hopefully this has shown how to create a settings list that can be used in a dialog where I believe most people will be intending to use it.

My thanks to mark_williams and synov on the Nokia forum for providing some code to help get this off the ground and to John Kern for proofreading and commenting on this article.


> Creating a CAknSettingItemList in a Dialog

your article is very good , but how can I add a item dynamicly?

thank you.

> Creating a CAknSettingItemList in a Dialog

Unfortunatly I am right in the middle of moving so I don't have a permanent base to test the idea below.

Personally I would create all the setting items I need in the resource and then use the SetHidden method to hide the items that are not relevant, that solution being the cleanest and thus more stable.

It looks like the API was never really intended to allow people to dynamically add or remove items, however the stuff below should be a starting point.

All CAknSettingItems are held in a CAknSettingItemArray, which may be obtained from the SettingItemArray() function. This array holds a collection of pointers to CAknSettingItem. So you should be able to add and remove items from the collection this way. You will probably need to call RecalculateVisibleIndicesL method in the array after the new item.

Finally you will need to call HandleChangeInItemArrayOrVisibility to update the listbox with the new items.

Dynamic CAknSettingItemList Example

People interested in creating dynamic setting lists can download a good example from Nokia:

> Creating a CAknSettingItemList in a Dialog

It seems, my link got lost, here it is again: http://sw.nokia.com/id/2e80a6f4-9d9b-45d1-b268-d01b862a7023/S60_Platform_Dynamic_Setting_List_Example_v1_0.zip

> Creating a CAknSettingItemList in a Dialog

http://sw.nokia.com/id/2e80a6f4-9d9b-45d1-b268-d01b862a7023/S60_Platform_Dynamic_Setting_List_Example_v1_0.zip

the example in the above link is using CCoeControl ( View) method to display setting list and dynamicall item creation. I want to create setting list in dialog and items should be created dynamically. How can I do this..?

> Creating a CAknSettingItemList in a Dialog

Thanks for this helpful article. And my request is same as above :) "how to add or remove a CAknSettingItem from the list" . There is no information about this at anywhere:(

> Creating a CAknSettingItemList in a Dialog

Extremely helpful article. I've used it to add a settings dialog to my own app. and it works just fine. Thanks to Paul for this extremely clear and useful tutorial.

> Creating a CAknSettingItemList in a Dialog

Nice article. Code works fine for me. However, when I try to add a new type of item to the custom control, my app crashes when an attempt to edit the new item is made. I can add additional editors as AVKON_SETTING_ITEM resources, and it works. But if I add other types of items, such as a slider, the app fails. The item will be properly displayed in the dialog, but when I choose the Select softkey the line:

iSettingsList->EditItemL( itemIndex, ETrue );

fails. Any ideas on what I might be doing wrong? Thanks, Dan

> Creating a CAknSettingItemList in a Dialog

just in case someone still wonders about this...

make sure you call

BaseConstructL(EAknEnableSkin);

in your AppUi ConstructL

> Creating a CAknSettingItemList in a Dialog

You, my friend, are a genius and a god send... lol.. After working with the very lame Nokia and Developing Series 60 book settings examples, I had gotten nada. These examples show how to create the settings list, but they are embedded in a completely rediculous, bloated, nonsence app that can't be mapped very easily to a real-world application.

Your example allowed me to add the settings list to my current application with ease. I can't thank you enough. Nokia and the book writers should follow your lead in creating examples. I thought Symbian was bad with docs... Nokia is even worse... at least for Series 60 2.1...lol

Okay.. I am done bashing... again, thanks for your very cogent example.

Creating a CAknSettingItemList in a Dialog

Thanks, very usefull sample code and good explanations!

Creating a CAknSettingItemList in a Dialog

how can i add CAknEnumeratedTextPopupSettingItem to the setting list items

Creating a CAknSettingItemList in a Dialog

Sorry, I don't have time to write one.

There is an example in the Series 60 Example code supplied with the SDK.

The sample is called SettingsList.

There is further information in s60_platform_avkon_ui_resources_setting_lists_v1_1_en.pdf in the S60 documents folder.

Creating a CAknSettingItemList in a Dialog

Paul Todd, you're my hero!

keep up the good work

Creating a CAknSettingItemList in a Dialog

Hi Paul, Thanks for your useful article. But if I follow the same approach to create a setting list (with setting item CAknBinaryPopupSettingItem) to include into a form instead of dialog, it crashes with the panic EXEC 3.

What could be the actaul reason.

Thanks
 Anand