You Are Here:

Community: Wiki

This page was last modified on 12 April 2009, at 20:08.

Use CAknEnumeratedTextPopupSettingItem dynamically at runtime

From Forum Nokia Wiki

Use CAknEnumeratedTextPopupSettingItem dynamically at runtime

In an article -- "Create Dynamic Settings Pages", 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.

Contents

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->ResetAndDestroy();
texts->AppendL(new CAknEnumeratedText(1, KFirst().AllocL()));
texts->AppendL(new CAknEnumeratedText(2, KSecond().AllocL()));
texts->AppendL(new CAknEnumeratedText(10, KThird().AllocL()));
popTextArr->ResetAndDestroy();
popTextArr->AppendL(KFirst().AllocL());
popTextArr->AppendL(KSecond().AllocL());
popTextArr->AppendL(KThird().AllocL());
}
}
 
void CMyTextPopupSettingItem::CompleteConstructionL()
{
CAknEnumeratedTextPopupSettingItem::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.
this->SetExternalValue(item->EnumerationValue());
}
}
CAknEnumeratedTextPopupSettingItem::LoadL();
}

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 );
SettingPage()->SetSettingPageObserver(this);
 
SettingPage()->SetSettingTextL(SettingName());
 
SettingPage()->ExecuteLD(CAknSettingPage::EUpdateWhenChanged);
SetSettingPage(0);
}

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();
 
private:
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);
break;
}

See also

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fE25E455E25A6E2582E25E454E25BE44E2595E25E455E259CE25A8E25E456E2594E25B6E25E454E25BBE25B6E25E457E25AE45E25B1E25E455E2588E259BE25E455E25BBE25BAE25E457E259FE25AE44E25E454E25BFE25A1X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
RDF Facets: qfnZuserE5FtagQSxcaknenumeratedteE78tpopupsettingitemX qfnZuserE5FtagQSxdynamicallyX qfnZuserE5FtagQSxruntimeX qfnZuserE5FtagQSxsettingE20itemE20lisE206X qfnZuserE5FtagQSxsettingE20listX qfnZuserE5FtagQSxsettingsX