自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Symbian學(xué)習(xí)筆記(10)——使用ListBox

系統(tǒng)
symbian中的ListBox比較復(fù)雜也是比較常用的,我只能先從最簡單的CAknSingleStyleListBox入手來嘗試看看。太復(fù)雜的東西不是我這樣的新手要立刻去明白的。
symbian中的ListBox比較復(fù)雜也是比較常用的,我只能先從最簡單的CAknSingleStyleListBox入手來嘗試看看。太復(fù)雜的東西不是我這樣的新手要立刻去明白的。

  先聲明一個列表組件:CAknSingleStyleListBox* iListBox;

  然后在Container的ConstructL中去創(chuàng)建它:

 

void CUniNewsAppContainer::ConstructL(const TRect& aRect) ...{
    CreateWindowL();
   
    //add your code here ...

    //construct a listbox
    iListBox = new(ELeave) CAknSingleStyleListBox
    iListBox->SetContainerWindowL( *this);
    iListBox->SetListBoxObserver(this);
    iListBox->ConstructL(this,EAknListBoxSelectionList|EAknListBoxLoopScrolling);
      
    iListBox->CreateScrollBarFrameL(ETrue);
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,CEikScrollBarFrame::EOn);
    iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
    iListBox->SetRect(aRect);   
   
    SetRect(aRect);
    ActivateL();
}

  這里有幾句話,一是SetScrollBarVisibilityL設(shè)置使用滾動條,二是ItemDrawer()->ColumData()->EnableMarqueeL()讓選中的文本超長后可以左右滾動。

  有一點比較奇怪,我得先設(shè)置ListBox的Rect才能設(shè)置整個Container的Rect?否則ListBox會不占整個主面板的位置。

  接著在合適的地方需要去給ListBox增加內(nèi)容:

void CUniNewsAppContainer::InitListBox(TInt tabId)
...{
    if(iListBox==NULL) return;

   
    CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
    TBuf<256> str;
   
    list->Reset();
           
    CUniNewsAppView * appView = STATIC_CAST(CUniNewsAppUi*,iCoeEnv->AppUi())->iAppView;
    RArray<TNewsContent>* rc = appView->iChannelHandler->GetContents();
    for(TInt i=0;i<rc->Count();i++)
    ...{
        if( (*rc)[i].pid==tabId)...{
            str.FillZ(str.MaxLength());
            str.Format(KITEMFORMAT,(*rc)[i].title);
            list->AppendL(str);
        }
    }
      
    iListBox->HandleItemAdditionL();
    iListBox->SetFocus( ETrue );
    iListBox->SetCurrentItemIndexAndDraw(appView->iListIndex);
    iListBox->ActivateL();
   
    iListBox->DrawNow();   
}

  這里的HandleItemAdditionL()通知一下ListBox模型作了增加操作,同樣還有一個HandleItemRemovalL()則是通知ListBox作了一個刪除操作。

  這里的KITEMFORMAT定義是"\t%S"。這里的格式似乎挺重要的,一般是:圖標(biāo)ID\t題頭字串\t主要字串\t圖標(biāo)ID\t圖標(biāo)ID。

  我這里因為沒有用到圖標(biāo)所以是一個\t%S,這個\t不可省略。如果用圖標(biāo),則變成%d\t%S了,同時還要增加iconArray在創(chuàng)建iListBox的時候。

 

CAknIconArray* icons =new(ELeave) CAknIconArray(2);
CleanupStack::PushL(icons);
icons->ConstructFromResourceL(R_ICON_LISTICONS);
iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);   
CleanupStack::Pop();

  在ListBox中有一個叫Model()的還有一個叫View()的,從名字上就可以看出它們的含義了。前面我們從Model中操作列表內(nèi)容,而我們可以從View中獲取ItemDrawer去操作列表顯示

  的一些參數(shù),但是我覺得有一點不爽的是,缺省生成的列表框字體比較大,不是太喜歡,在網(wǎng)上搜了一下,似乎那個設(shè)置字體的方法對我的機(jī)器不管用?

  iListBox->ItemDrawer()->SetFont(ApacPlain12());

  不過有一種方法是可行的,只是比較麻煩,那就是自己去實現(xiàn)ListBox,以及它的ItemDrawer。在網(wǎng)上看到的代碼我試了一下,還行。方法如下。

  第一步作一個自己的ItemDrawer:

 

class CCustomListItemDrawer: public CListItemDrawer
...{
public:
    CCustomListItemDrawer(const CEikTextListBox& aListBox);
    ~CCustomListItemDrawer();

private:
    virtual void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect,
         TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool aViewIsDimmed,
         TBool aItemIsSelected) const;

public:
    void SetIconArray(CArrayPtr<CGulIcon>* aIconArray);
    TSize MaxIconSize() const;

private:
    void DeleteIconArray();
    void CalculateMaxIconSize();

private:
    const CEikTextListBox& iListBox;
    CArrayPtr<CGulIcon>*   iIconArray;
    TSize                  iMaxIconSize;
};

  實現(xiàn)的代碼中最重要的就是那個DrawActualItem方法負(fù)責(zé)具體的繪制工作,從它的參數(shù)表中足夠得到繪制所需的信息,剩下的事情就是用SystemGc去繪制。

  第二步是作一個自己的ListBox控件:

 

class CCustomListBox: public CEikTextListBox
    ...{
public: // constructors
    CCustomListBox();
    void ConstructL(const CCoeControl* aParent, TInt aFlags = 0);

public: // from CEikTextListBox
    virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
        TEventCode aType);

private: // from CEikTextListBox
    virtual void CreateItemDrawerL();
    };

  在它的CreateItemDrawerL()中創(chuàng)建成員iItemDrawer = new (ELeave) CCustomListItemDrawer(*this)。而OfferKeyEvent主要的作用是處理上下方向鍵。

  關(guān)于ListBox的使用,可以參考這個地址:http://pagesperso-orange.fr/klisa/3650/ListBox/page01.html

【編輯推薦】

  1. Symbian每6個月發(fā)布一款新開源操作系統(tǒng)
  2. 微軟建WindowsMarketplace 完善智能機(jī)平臺
  3. 大力模仿Android 傳微軟WM6.5可裝插件
責(zé)任編輯:龐桂玉 來源: it168
相關(guān)推薦

2009-04-12 09:02:32

Symbian諾基亞移動OS

2009-04-12 09:06:00

Symbian諾基亞移動OS

2009-04-12 08:59:05

Symbian諾基亞移動OS

2009-04-12 09:00:08

Symbian諾基亞移動OS

2009-04-12 09:01:05

Symbian諾基亞移動OS

2009-04-12 09:03:50

Symbian諾基亞移動OS

2009-04-12 08:57:50

Symbian諾基亞移動OS

2009-08-12 15:50:40

C# ListBox

2009-04-12 08:36:09

Symbian諾基亞移動OS

2009-04-12 08:46:43

Symbian諾基亞移動OS

2009-04-12 08:51:50

Symbian諾基亞移動OS

2009-04-12 09:07:17

Symbian諾基亞移動OS

2009-04-12 08:45:32

Symbian諾基亞移動OS

2009-04-12 08:48:47

Symbian諾基亞移動OS

2009-04-12 08:50:08

Symbian諾基亞移動OS

2011-06-16 16:21:06

Qt Symbian FAQ

2010-03-16 10:51:35

Silverlight

2009-04-12 08:52:52

Symbian諾基亞移動OS

2011-06-16 15:59:40

Qt Symbian

2012-05-24 09:38:08

Symbian
點贊
收藏

51CTO技術(shù)棧公眾號