how to create list box example
来源:互联网 发布:送闺蜜新年礼物 知乎 编辑:程序博客网 时间:2024/05/16 11:10
List box example
From Forum Nokia Wiki
The CListboxContainer illustrates how to use list boxes in your application. The main function where the list box is made is named MakeListBoxL(). Inside it the list box is constructed as CAknSingleLargeStyleListBox. If you want to change it to something else, you can one of the following S60 list box types:
- CAknSingleStyleListBox
- CAknSingleNumberStyleListBox
- CAknSingleHeadingStyleListBox,
- CAknSingleGraphicStyleListBox
- CAknSingleGraphicHeadingStyleListBox
- CAknSingleNumberHeadingStyleListBox
- CAknSingleLargeStyleListBox
- CAknDoubleStyleListBox
- CAknDoubleNumberStyleListBox
- CAknDoubleLargeStyleListBox
- CAknDoubleGraphicStyleListBox
- CAknDoubleTimeStyleListBox
In GetArrayL() you need to construct the text stringsfor the list box according to the selected list box type. When usingS60 specific list boxes, the icon size will be automatically set by thelist box, so you don’t need to set any size for the icons.Remember to add CListboxContainer instance to control stack (withAddToStackL()) after creation to get notifications of key events inOfferKeyEventL().
CListboxContainer.cpp
#include "CListboxContainer.h"
#include <akniconarray.h>
#include <eikclbd.h>
CListboxContainer::CListboxContainer(void)
{
}
CListboxContainer::~CListboxContainer()
{
delete iMyListBox;
}
void CListboxContainer::ConstructL()
{
CreateWindowL();
SetRect(iEikonEnv->EikAppUi()->ClientRect());
ActivateL();
DrawNow();
}
void CListboxContainer::SizeChanged()
{
TRAP_IGNORE( MakeListBoxL() );
}
void CListboxContainer::HandleResourceChange(TInt aType)
{
TRect rect;
if ( aType==KEikDynamicLayoutVariantSwitch )
{
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
SetRect(rect);
}
CCoeControl::HandleResourceChange(aType);
}
void CListboxContainer::MakeListBoxL()
{
TInt MySetIndex(0);
if(iMyListBox)
{
MySetIndex = iMyListBox->CurrentItemIndex();
}
delete iMyListBox;
iMyListBox = NULL;
iMyListBox = new( ELeave ) CAknSingleLargeStyleListBox();
iMyListBox->ConstructL(this,EAknListBoxSelectionList);
CArrayPtr<CGulIcon>* icons =new( ELeave ) CAknIconArray(1);
CleanupStack::PushL(icons);
iMyListBox->Model()->SetItemTextArray(GetArrayL(icons));
iMyListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
//
// Inform the listbox of item additions.
// This should be done if you want your items displayed correctly
iMyListBox ->HandleItemAdditionL();
CleanupStack::Pop(icons);
iMyListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
iMyListBox->CreateScrollBarFrameL( ETrue );
iMyListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iMyListBox->SetRect(Rect());
iMyListBox->View()->SetListEmptyTextL(KtxNoData);
iMyListBox->ActivateL();
TInt ItemsCount = iMyListBox->Model()->ItemTextArray()->MdcaCount();
if(ItemsCount > MySetIndex && MySetIndex >= 0)
iMyListBox->SetCurrentItemIndex(MySetIndex);
else if(ItemsCount > 0)
iMyListBox->SetCurrentItemIndex(0);
UpdateScrollBar(iMyListBox);
iMyListBox->DrawNow();
}
CDesCArray* CListboxContainer::GetArrayL(CArrayPtr<CGulIcon>* aIcon)
{
CDesCArrayFlat* myArray = new(ELeave)CDesCArrayFlat(1);
CleanupStack::PushL(myArray);
// 1) Append Text string to myArray in here as "1/tMytext",
// where 1 is the zero based icon index
//
// Second and third icon indexes can also be specified in the form:
// "1/tMytext/t2/t3" where 2 and 3 are also zero-based icon indexes
//
// 2) Remember to load and add icons in here. Listbox will
// automatically resize iconsthus no need to set any size for them.
// Tip: you may find AknIconUtils::CreateIconLC and
// AknIconUtils::AvkonIconFileName() useful. In that case,
// include akniconutils.h and avkon.mbg
CleanupStack::Pop(myArray);
return myArray;
}
void CListboxContainer::UpdateScrollBar(CEikListBox* aListBox)
{
if (aListBox)
{
TInt pos(aListBox->View()->CurrentItemIndex());
if (aListBox->ScrollBarFrame())
{
aListBox->ScrollBarFrame()->MoveVertThumbTo(pos);
}
}
}
void CListboxContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
}
TKeyResponse CListboxContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aEventCode)
{
TKeyResponse Ret = EKeyWasNotConsumed;
if(iMyListBox)
{
Ret = iMyListBox->OfferKeyEventL(aKeyEvent,aEventCode);
}
return Ret;
}
CCoeControl* CListboxContainer::ComponentControl( TInt /*aIndex*/) const
{
return iMyListBox;
}
TInt CListboxContainer::CountComponentControls() const
{
if(iMyListBox)
return 1;
else
return 0;
}
CListboxContainer.h
#include <aknlists.h>
#include <gulicon.h>
_LIT(KtxNoData, "Empty list");
class CListboxContainer : public CCoeControl
{
public:
CListboxContainer(void);
void ConstructL(void);
~CListboxContainer();
public:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
CCoeControl* ComponentControl( TInt aIndex) const;
TInt CountComponentControls() const;
private:
virtual void SizeChanged();
virtual void HandleResourceChange(TInt aType);
void Draw(const TRect& aRect) const;
CDesCArray* GetArrayL(CArrayPtr<CGulIcon>* aIcon);
void MakeListBoxL(void);
void UpdateScrollBar(CEikListBox* aListBox);
private:
CAknSingleLargeStyleListBox* iMyListBox;
};
Related Links
- How to create a simple listbox
- Querying selection with list
- TSS000647 - Applying actions on list box items
- How to add Marquee effect in ListBox
- How to add ScrollBar in ListBox
- How to add additional data to the list box?
- Listbox creation using resource
- how to create list box example
- How to: Create a Numeric Text Box
- How to: Create a Custom List Definition
- How to: Create a Custom Action Specific to a List
- How to create readonly columns in MOSS 2007 custom list
- How to create Linked list using C/C++
- Python: how to create a list of n lists [[],[],[]]
- Java Tutorial: How to Create RESTful Java Client using Apache HttpClient – Example
- How to create Immutable Class and Object in Java - Tutorial Example
- How to Create and Evaluate XPath Expression in Java - Tutorial and Example
- How to create singleton
- How to create alarm
- How to create WCF
- How to Create Tables
- Example - how to implement INotifyDataErrorInfo
- Siebel HOW TO: How to create Products?
- Spring Form Tags - How to use Text Box, Radio Button, Check Box and Drop Down List in Spring
- How to Create a Customer
- 使用FileReference+HttpHandler实现文件上传/下载(Flex与.NET互操作)
- 动态url转化为静态url(url重定向)
- JavaScript与C#之间函数与变量的相互调用(转)
- 解析KML文件 , 获取Coordinates标签中的经纬度坐标值
- 函数模板与名字空间, 编译错误C2440
- how to create list box example
- BI走下神坛 商业分析或成新宠
- 网页图片验证码实验心得
- “/r/n”回车与换行
- VolumeParticle(1)
- how to use the CAknwaitDialog
- 11
- 匈牙利 规范
- isag webservice axis