Namespaces

Variants
Actions

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.

如何根据一个设置列表项的值动态显示/隐藏另一个项

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
文章
翻译:
chenziteng
最后由 hamishwillee 在 22 Dec 2011 编辑


假定一个设置列表中有若干项,根据需要可能显示所有项,也可能根据某些项的值决定隐藏其它项。本文介绍了如何实现这一需求。

在创建设置列表时可以通过以下代码隐藏某一项。

CAknTextSettingItem* item3 = new (ELeave) CAknTextSettingItem(4, iAccountTag);
CleanupStack::PushL(item3);
item3->SetEmptyItemTextL( KEmptyText );
// The same resource id can be used for multiple text setting pages.
item3->ConstructL(isNumberedStyle, 4, KName2, icons, R_NAME_SETTING_PAGE, -1);
iItemList->SettingItemArray()->AppendL(item3);
item3->SetHidden(ETrue); //// HIDDEN
CleanupStack::Pop(item3);

当某个项的值发生变化时,可以用以下代码动态显示/隐藏其它项。

TKeyResponse CMySettingContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType )
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
else if(iItemList)
{
TKeyResponse keyResp =
iItemList->OfferKeyEventL(aKeyEvent, aType);
 
if(keyResp == EKeyWasConsumed && aKeyEvent.iCode == EKeyOK)
{
iItemList->StoreSettingsL();//Get settings
 
if(iAccountEmail.Find(KFlickrEmail)!=KErrNotFound)
{
((*iItemList->SettingItemArray())[2])->SetHidden(EFalse);
iItemList->HandleChangeInItemArrayOrVisibilityL();
iFlickrEnabled=ETrue;
}
else
{
((*iItemList->SettingItemArray())[2])->SetHidden(ETrue);
iItemList->HandleChangeInItemArrayOrVisibilityL();
iFlickrEnabled=EFalse;
}
}
 
return keyResp;
}
else
{
return EKeyWasNotConsumed;
}
}

完整的示例程序:

Ftsmwnjd(HideSettingItemDynamically).zip

示例程序的屏幕截图:

SettingsListOn.JPG SettingsListOff.JPG

This page was last modified on 22 December 2011, at 05:05.
28 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.

×