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

兼容于
平台: S60 1st Edition, S60 2nd Edition and FP1, FP2, FP3, S60 3rd Edition and FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
S60 2nd Edition FP2
S60 2nd Edition (initial release)
S60 1st Edition

文章
翻译:
huwell
最后由 hamishwillee 在 08 Aug 2012 编辑

描述

下面的代码示例演示了如何响应用户选定的列表框项。

这里介绍一下如何生成一个简单列表框 How to create a simple listbox in Symbian C++

我们可以捕捉任何键盘事件借以产生各种响应(如弹出一个对话框),我们可以通过OfferKeyEventL()方法来处理


解决方案

TKeyResponse CMyExampleAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
switch(aKeyEvent.iCode)
{
case EKeyUpArrow:
case EKeyDownArrow:
{
// Forward up and down key press events to the list box
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
case EKeyOK: // display an information note when item is selected
{
_LIT(KFormatMessage, "Selected item: %d");
TInt idx = iListBox->CurrentItemIndex();
TBuf<32> message;
message.Format(KFormatMessage, idx);
CAknInformationNote* Note = new (ELeave) CAknInformationNote;
Note->ExecuteLD(message);
return EKeyWasConsumed;
}
default:
break;
}
return EKeyWasNotConsumed;
}


注意要加上这行代码:

    AddToStackL( iAppView );

在AppUi的构造函数ConstructL()中,要将该view/container添加到control stack中以便接收OfferKeyEventL()调用

响应list box的选择事件通常使用list box的观察器MEikListBoxObserver来实现:

class CYourContainer : public CCoeControl,public MEikListBoxObserver
{
public:
............
 
void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);
............
};
 
void CYourContainer ::HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType )
{
TInt index = aListBox->CurrentItemIndex();
if( index < 0 )
return;
 
if( aEventType == MEikListBoxObserver::EEventEnterKeyPressed )
{
_LIT(KFormatMessage, "Selected item: %d");
TBuf<32> message;
message.Format(KFormatMessage, index );
CAknInformationNote* Note = new (ELeave) CAknInformationNote;
Note->ExecuteLD(message);
}
}
This page was last modified on 8 August 2012, at 02:41.
221 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.

×