第一步,
#include
#include "AppUi.h"
class CAknSingleNumberStyleListBox;
class CDesC16Array;
class CCallAppAppContainer : public CCoeControl, MCoeControlObserver
{
......
public:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
public:
virtual void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
private:
CAknSingleNumberStyleListBox *iListBox;
CDesC16Array *iItems;
};
第二步, 在控件构造函数中生成对象,并设置基本参数
void CContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//生成对象
iListBox = new( ELeave ) CAknSingleNumberStyleListBox();
iListBox->SetContainerWindowL( *this );
iListBox->SetObserver(this);
iListBox->ConstructL( this,
EAknListBoxSelectionList | EAknListBoxLoopScrolling );
//设置滚动条
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()
->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto );
// Get the item list
// listbox 中的数据项的数组
iItems = static_cast
(iListBox->Model()->ItemTextArray());
SetRect(aRect);
ActivateL();
}
void CCallAppAppContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}
第三步,在适当的位置,添加数据项。
iItems->AppendL( _T("TTTTTT") );
TInt count = iItems->Count();
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndexAndDraw( count - 1 );
第四步,控制用户按键
TKeyResponse Container::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if ( aType != EEventKey )
{
return EKeyWasNotConsumed;
}
switch ( aKeyEvent.iCode )
{
// Up & Down arrow key's event transfer to list box
case EKeyUpArrow:
case EKeyDownArrow:
if ( iListBox )
{
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
break;
case EKeyLeftArrow:
case EKeyRightArrow:
return EKeyWasConsumed;
break;
case EKeyDelete:
case EKeyBackspace:
return EKeyWasConsumed;
break;
default:
break;
}
return EKeyWasNotConsumed;
}
阅读(359) | 评论(0) | 转发(0) |