ListBox的一点心得

转自:http://www.symbianx.cn/viewthread.php?tid=47

 

这两天在看SDK EXAMPLE的LISTBOX例子,有一些心得与大家分享,有什么错误请大家指出。在例子中就用了2个LISTBOX的类,一个是 CEikColumnListBox;另一个是CEikFormattedCellListBox。它们分别对应SINGLE和DOUBLE两种表现形式。下面用代码来说明一下。

 

 

CEikColumnListBox* iColListBox;
CEikFormattedCellListBox* iForListBox;

iColListBox = new (ELeave) CAknSingleStyleListBox();
iForListBox = new (ELeave) CAknDoubleGraphicStyleListBox();

iColListBox->SetContainerWindowL( *this );
iForListBox->SetContainerWindowL( *this );

//从资源文件中生成LISTBOX
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC( reader, R_TEST_SINGLE);
iColListBox->ConstructFromResourceL( reader );

CEikonEnv::Static()->CreateResourceReaderLC( reader, R_TEST_DOUBLE);
iForListBox->ConstructFromResourceL( reader );

//设置SCROLLBAR
iColListBox->CreateScrollBarFrameL( ETrue );
iColListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );

iForListBox->CreateScrollBarFrameL( ETrue );
iForListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );

//适合窗口大小
iColListBox->SetRect(Rect());
iForListBox->SetRect(Rect());

//激活
iColListBox->ActivateL();
iForListBox->ActivateL();


//资源.RSS

RESOURCE LISTBOX r_text_single
{
// 给定要生成LISTBOX的ITEMS
array_id = r_array_single;
// LISTBOX的标示
flags = EAknListBoxSelectionList;
}

RESOURCE LISTBOX r_text_double
{
array_id = r_array_double;
flags = EAknListBoxSelectionList;
}

//请注意r_array_single和r_array_double的不同。
// \t 就是分割符。
// "0\tAAAAAA\taaaaaa"最前的0表示在*.mbm中序号为0的图片加到LISTBOX的ITEM前
RESOURCE ARRAY r_array_single
{
items =
{
LBUF
{
txt = " \taaaaaa";
},
LBUF
{
txt = " \tbbbbbb";
}
};
}

RESOURCE ARRAY r_array_double
{
items =
{
LBUF
{
txt = "0\tAAAAAA\taaaaaa";
},
LBUF
{
txt = "0\tBBBBBB\tbbbbbb";
}
};
} 
posted @ 2010-04-21 21:09  秋天的风  阅读(220)  评论(0编辑  收藏  举报