Use CAknEnumeratedTextPopupSettingItem dynamically at runtime(转)

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

  [hide]

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

转载于:https://www.cnblogs.com/yaoliang11/archive/2010/10/12/1848907.html

failed to dynamically imported module是一种错误信息,表示在动态导入模块时出现了错误。具体的错误原因可能有很多种,需要进一步检查代码和环境设置来确定具体的问题所在。由于引用中没有提供更多的相关信息,我无法给出更加具体的解决方法。但是,可以参考以下一般性的解决步骤来处理这个问题: 1. 检查模块的路径和文件名是否正确,并确保文件存在。 2. 检查网络连接是否正常,如果是从远程服务器加载模块,可能是网络问题导致加载失败。 3. 检查导入模块的语法是否正确,特别是在使用动态导入的情况下,要确保语法符合规范。 4. 检查代码中是否存在其他可能导致加载失败的问题,例如权限问题、版本兼容性等。 如果以上方法仍然无法解决问题,建议查阅相关的文档或寻求开发者社区的帮助,以获得更专业的支持和解决方案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [TypeError: Failed to fetch dynamically imported module:](https://blog.csdn.net/m0_50080847/article/details/127360409)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Vue3+TS错误解决 Failed to fetch dynamically imported module:](https://blog.csdn.net/weixin_45791692/article/details/124119879)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值