Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Use CAknEnumeratedTextPopupSettingItem dynamically at runtime

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Created: dougcn (14 Jun 2008)
Last edited: hamishwillee (02 Jul 2012)

Use CAknEnumeratedTextPopupSettingItem dynamically at runtime

In an article -- "Create Dynamic Settings Pages using Symbian C++", there is a section describing how to "Adding Enumerated Text Item". See it for details.

In this article, I will introduce another way -- creating a CAknEnumeratedTextPopupSettingItem-derived class to use dynamic data at runtime.

An important note: "Setting Item Lis 6" panic will occur when no match found in the EnumeratedTextArray, not zero-based. To demonstrate this, I will use 1,2,10 for the enumeration values, different from those(0,1,10) in the above article. We will see how to fix it also.


Create test data

First we need some test data, and then load the test data when calling CompleteConstructionL() function.

void CMyTextPopupSettingItem::LoadTestDataL()
_LIT(KFirst, "first (1)");
_LIT(KSecond, "second (2)");
_LIT(KThird, "third (10)");
// Get the value array
CArrayPtr<CAknEnumeratedText>* texts = this->EnumeratedTextArray();
CArrayPtr<HBufC>* popTextArr = this->PoppedUpTextArray();
// Empty it
if (texts && popTextArr)
texts->AppendL(new CAknEnumeratedText(1, KFirst().AllocL()));
texts->AppendL(new CAknEnumeratedText(2, KSecond().AllocL()));
texts->AppendL(new CAknEnumeratedText(10, KThird().AllocL()));
void CMyTextPopupSettingItem::CompleteConstructionL()
LoadTestDataL(); // overwrite the resource definitions.

Check target value

We must check whether the target value, iValue, is in the loaded array or not. If not, it definitely causes a panic -- "Setting Item Lis 6". In that case, we will choose the first item as the default one. See below:

void CMyTextPopupSettingItem::LoadL()
CArrayPtr<CAknEnumeratedText>* texts = this->EnumeratedTextArray();
TInt selectedIndex = this->IndexFromValue(iValue);
if (selectedIndex < 0) // no match found.
if (texts->Count() > 0)
// choose the first item as default one.
CAknEnumeratedText* item = texts->At(0);
// reset external value to the default one.

constructor, etc

The constructor of CMyTextPopupSettingItem:

CMyTextPopupSettingItem::CMyTextPopupSettingItem( TInt aIdentifier, TInt& aValue )
: CAknEnumeratedTextPopupSettingItem(aIdentifier, aValue), iValue(aValue)

The implementation of CreateAndExecuteSettingPageL:

void CMyTextPopupSettingItem::CreateAndExecuteSettingPageL()
CAknSettingPage* dlg = CreateSettingPageL();
SetSettingPage( dlg );

The header file

class CMyTextPopupSettingItem : public CAknEnumeratedTextPopupSettingItem
public: // Constructor
CMyTextPopupSettingItem( TInt aIdentifier, TInt& aValue );
void LoadL();
protected: // Functions from base classes
void CreateAndExecuteSettingPageL();
void CompleteConstructionL();
private: // custom methods
void LoadTestDataL();
TInt iValue;

Use CMyTextPopupSettingItem

In the CreateSettingItemL method of your Setting List container, add some code like this:

    case EMyAppItemTest:
// iData = 1; // here you can specify the default value to test the class we have just created.
// iData = 0; // This will cause a panic if no fixes in LoadL function.
settingItem = new (ELeave) CMyTextPopupSettingItem(aIdentifier, iData);

See also

This page was last modified on 2 July 2012, at 04:34.
26 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.