Creating a radio button settings page using Symbian C++
Article Metadata
Tested with
Devices(s): Nokia 6220 Classic
Compatibility
Platform(s): S60 3rd Edition
Article
Keywords: CAknRadioButtonSettingPage, MAknSettingPageObserver, CAknRadioButtonSettingPage::SetSettingPageObserver(), CAknRadioButtonSettingPage::ExecuteLD(), MAknSettingPageObserver::HandleSettingPageEventL()
Created: aknyman
(25 Sep 2008)
Last edited: hamishwillee
(14 Jun 2012)
Contents |
Overview
This code snippet shows how to create a radio button settings page using the class CAknRadioButtonSettingPage. After implementing the interface MAknSettingPageObserver, the UI class will be able to capture events of type TAknSettingPageEvent.
This snippet can be self-signed.
Resource file (.rss)
#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
//...
RESOURCE AVKON_SETTING_PAGE r_example_setting_page
{
label = "Title";
type = EAknCtPopupSettingList;
editor_resource_id = r_example_setting_list;
}
RESOURCE POPUP_SETTING_LIST r_example_setting_list
{
flags = 0;
}
RESOURCE ARRAY r_example_options
{
items =
{
LBUF { txt = "option0";},
LBUF { txt = "option1";},
LBUF { txt = "option2";}
};
}
MMP file
The following libraries are required:
LIBRARY avkon.lib
LIBRARY eikctl.lib
LIBRARY eikcoctl.lib
LIBRARY bafl.lib
Header file
#ifndef __EXAMPLEAPPUI_H__
#define __EXAMPLEAPPUI_H__
// INCLUDES
#include <aknappui.h>
#include <AknSettingPage.h> //For CAknSettingPage, TAknSettingPageEvent
#include <eiklbx.h> //For CEikListBox
#include <badesca.h> //For CDesCArrayFlat
#include <aknradiobuttonsettingpage.h> //For CAknRadioButtonSettingPage
// CLASS DECLARATION
// CExampleAppUi application UI class.
class CExampleAppUi : public CAknAppUi, public MAknSettingPageObserver
{
//...
public: //From MAknSettingPageObserver
void HandleSettingPageEventL(CAknSettingPage* aSettingPage,
TAknSettingPageEvent aEventType);
//...
private:
void ShowRadioButtonSettingPageL();
void ShowDynamicRadioButtonSettingPageL();
CDesCArrayFlat* CreateRadionButtonOptionsLC();
//...
private:
//data
TInt iSelection;
};
#endif //__EXAMPLEAPPUI_H__
Source file
#include "ExampleAppUi.h"
//...
void CExampleAppUi::ShowRadioButtonSettingPageL()
{
CDesCArrayFlat *array = CEikonEnv::Static()->
ReadDesCArrayResourceL(R_EXAMPLE_OPTIONS);
CleanupStack::PushL(array);
CAknRadioButtonSettingPage* dialog =
new (ELeave) CAknRadioButtonSettingPage(R_EXAMPLE_SETTING_PAGE,
iSelection, array);
CleanupStack::PushL(dialog);
dialog->ConstructL();
CleanupStack::Pop();//dialog
dialog->SetSettingPageObserver(this);
//ExecuteLD() enumeration controls how often the setting page updates the
//externally held client object (EUpdateWhenChanged, EUpdateWhenAccepted)
dialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged);
CleanupStack::PopAndDestroy(); //array
}
void CExampleAppUi::ShowDynamicRadioButtonSettingPageL()
{
CDesCArrayFlat *array = CreateRadionButtonOptionsLC();
CAknRadioButtonSettingPage* dialog =
new (ELeave) CAknRadioButtonSettingPage(R_EXAMPLE_SETTING_PAGE,
iSelection, array);
CleanupStack::PushL(dialog);
dialog->ConstructL();
CleanupStack::Pop();//dialog
dialog->SetSettingPageObserver(this);
dialog->ExecuteLD(CAknSettingPage::EUpdateWhenChanged);
CleanupStack::PopAndDestroy(); //array
}
CDesCArrayFlat* CExampleAppUi::CreateRadionButtonOptionsLC()
{
TInt itemCount = 3;
CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(itemCount);
CleanupStack::PushL(array);
array->AppendL(_L("option0"));
array->AppendL(_L("option1"));
array->AppendL(_L("option2"));
return array;
}
// Handles an event of type aEventType reported by the Setting Page to this observer.
void CExampleAppUi::HandleSettingPageEventL(CAknSettingPage* aSettingPage,
TAknSettingPageEvent aEventType)
{
if (aEventType == EEventSettingOked)
{
CEikListBox* listBox = (CEikListBox*) aSettingPage->EditorControl();
TInt selection = listBox->CurrentItemIndex();
//do something...
}
else if (aEventType == EEventSettingChanged)
{
//do something...
}
else if (aEventType == EEventSettingCancelled)
{
//do something...
}
else
{
//unknown type, do something...
}
}
Postconditions
The radio button setting page has been shown and the events (ok, cancel, change) have been captured.


(no comments yet)