首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian >> Symbian入门 >> 正文
Symbian Dynamic ListBox
作者:zhaotaob…    文章来源:本站原创    更新时间:2006-6-20 8:48:40

这些天一直在弄Symbian的ListBox,做个简单的总结——动态列表的建立方法:

1. MMP文件中需要的库:
LIBRARY euser.lib apparc.lib cone.lib eikcore.lib
LIBRARY eikcoctl.lib avkon.lib eikctl.lib bafl.lib
2. 在资源文件中定义ListBox 资源:
   RESOURCE LISTBOX r_notebook_listbox
 {
 flags = EAknListBoxSelectionList | EAknListBoxLoopScrolling;
 }

3. 定义拥有ListBox的控件类,使其从CCoeControl,和MEikListBoxObserver 公有继承,并在类中定义ListBox为数据成员:
    #include <aknlists.h> // CAknSingleStyleListBox
#include <barsread.h> // TResource Reader
#include <e32def.h> // STATIC_CAST
#include <eikclbd.h> // CColumnListBoxData
#include <eikmenub.h> // CEikMenuBarclass
#include <stringloader.h> // StringLoader
#include <uikon.hrh> // TKeyCode #defines

CContainer : public CCoeControl, MEikListBoxObserver
{
// Other Code
private:
  CAknColumnListBox*  iList; 
}
CAknColumnListBox 为ListBox的基类。

4. 建立列表:
   void CreateListL()
{
 iList = new (ELeave) CAknSingleStyleListBox;
 iList->SetContainerWindowL(*this);
 
 TResourceReader reader;
 CEikonEnv::Static()->CreateResourceReaderLC(reader, R_NOTEBOOK_LISTBOX);
  iList->ConstructFromResourceL(reader);
 CleanupStack::PopAndDestroy();
}

5. 加载列表项:
   void SetupListItemsL()
{
 CTextListBoxModel* model = iList->Model();
 model->SetOwnershipType (ELbmOwnsItemArray);
  CDesCArray* savedArray = STATIC_CAST(CDesCArray*, model->
ItemTextArray());
 LoadSavedL(*savedArray);
}

void LoadSavedL(CDesCArray& aArray)
{
 _LIT (KString,"\tSelect%d");
 TBuf <16> aString;
 for (TInt i = 1; i< 10; i++)
  {
  aString.Format(KString(),i);
  aArray.AppendL (aString);
  }
}
首先取得列表的模型,获取模型中的列表项数组,将列表项逐个添加到列表项数组里。

6. 设置滚动条:
   void SetupScrollBarsL()
{
 iList->CreateScrollBarFrameL();
 iList->ScrollBarFrame()->SetScrollBarVisibilityL(
  CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
}

7. 其他控件属性或函数的设置:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
 if (iList)
  return iList->OfferKeyEventL (aKeyEvent, aType);
 else
  return EKeyWasNotConsumed;
}

void SizeChanged()
    {
    iList->SetExtent( TPoint(0,0), iList->MinimumSize() );
}

void Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
 gc.Clear(aRect);
}

相关文章:
如何获取ListBox当前列表项(ListBoxItem)中的文本
如何创建listbox
如何给ListBox添加滚动效果
防火墙日志模块的开发
对IP地址的存取技巧
各种资源的定义
态生成的对话框上的Listbox加上Scrollbar
在listbox中怎么处理所选项的事件
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号