Статья базируется на материалах англоязычной части Wiki, все они перечислены в разделе ссылки.
Contents |
ChoiceList API - это новый UI компонент для выбора элементов из вертикального списка. В данной статье мы рассмотрим пример работы с этим API.
...
...
#include <aknchoicelist.h>
// CLASS DECLARATION
class CChoiceListAppView : public CCoeControl, public MCoeControlObserver
{
.....
.....
//From MCoeControlObserver
void HandleControlEventL(CCoeControl *aControl,TCoeEvent aEventType);
//Вспомогательные функции приложения
void CreateChoiceListL();
//From CCoeControl
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
.....
private:
CAknChoiceList* iChoiceList;
....
};
// -----------------------------------------------------------------------------
// CChoiceListAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CChoiceListAppView::ConstructL(const TRect& aRect)
{
// Создаем окно
CreateWindowL();
CreateChoiceListL();
....
....
// Устанавливаем размеры окна
SetRect(aRect);
// Активизируем окно
ActivateL();
}
void CChoiceListAppView::CreateChoiceListL()
{
CDesCArray* itemArray = new (ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(itemArray);
itemArray->AppendL(_L("First"));
itemArray->AppendL(_L("Second"));
itemArray->AppendL(_L("Third"));
iChoiceList = CAknChoiceList::NewL(this, itemArray);
CleanupStack::Pop(itemArray);
iChoiceList->SetContainerWindowL(*this);
iChoiceList->SetObserver(this);
iChoiceList->SetRect(TRect ( TPoint(100,200), TSize(120,10) ) );
}
void CChoiceListAppView::HandleControlEventL(CCoeControl *aControl,TCoeEvent aEventType)
{
if(iChoiceList == aControl)
{
switch(aEventType)
{
case EEventStateChanged:
{
TInt index = iChoiceList->SelectedIndex();
_LIT(KMenuItem,"%d is selected");
TBuf<20> buf;
buf.Format(KMenuItem(), index+1);
CAknInformationNote* info = new (ELeave) CAknInformationNote;
info->ExecuteLD(buf);
}
break;
}
}
}
TInt CChoiceListAppView::CountComponentControls() const
{
return 1; // возвращаем число компонентов в контейнере
}
CCoeControl* CChoiceListAppView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iChoiceList;
default:
return NULL;
}
}
// -----------------------------------------------------------------------------
// CChoiceListAppView::~CChoiceListAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CChoiceListAppView::~CChoiceListAppView()
{
....
....
if(iChoiceList)
{
delete iChoiceList;
iChoiceList = NULL;
}
}
При подготовке статьи использованы следующие материалы:
No related wiki articles found