×
Namespaces

Variants
Actions

处理与触摸相关的MEikListBoxObserver新事件

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 22 Oct 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS001148


  • 开发伙伴平台:

S60 5th Edition


  • 详细描述

S60第五版支持触摸事件。所有的AVKON UI控件都可以处理触摸界面事件,你无需另外完成什么。如果你的UI控件中有一个listbox,它将需要使用MEikListBoxObserver来监听所有listbox事件。你需要处理和触摸界面相关的下列新事件

* EEventItemClicked            // Item single-tap event
* EEventItemDoubleClicked // Item two-taps event
* EEventPenDownOnItem // Pen is down and over an item
* EEventItemDraggingActioned // Pen is dragged from item to another

注意CAknSingleStyleListBox已经它的AVKON基类中CAknColumnListBox::HandlePointerEventL()处理了触摸界面事件。不要去重载这个功能函数。

MMP文件

需要下列链接库

LIBRARY avkon.lib
LIBRARY eikcoctl.lib
LIBRARY eikctl.lib

头文件

#include <aknlists.h> // CAknSingleStyleListBox
#include <eiklbo.h> // MEikListBoxObserver


源文件

这里使用CAknSingleStyleListBox控件,在ConstructL()中生成

void CMyContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
 
// Initialize component array
InitComponentArrayL();
 
// Create listbox
iSearchListBox = new (ELeave) CAknSingleStyleListBox;
iSearchListBox->SetContainerWindowL(*this);
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, R_MY_LISTBOX);
iSearchListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); //reader
 
// --> Start event listening
iSearchListBox->SetListBoxObserver(this);
 
// Enable scrollbars
iSearchListBox->CreateScrollBarFrameL(ETrue);
iSearchListBox->ScrollBarFrame()
->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
CEikScrollBarFrame::EAuto);
 
Components().AppendLC(iSearchListBox,1);
CleanupStack::Pop( iSearchListBox );
 
SetRect(aRect);
ActivateL();
}


Listbox事件的监听部分完成如下。注意新的EEventItemDoubleClicked事件就是和触摸界面相关的,而EEventEnterKeyPressed事件则是老的选择键事件(S60第三版中)

void CMyContainer::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
{
if (aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked)
{
// TODO: Listbox got double click, what to do?
// From CEikListBox::CurrentItemIndex() you could get the selected row...
}
}
This page was last modified on 15 December 2011, at 09:20.
30 page views in the last 30 days.