从下边弹出一个列表实现单选



Includes:
#include <aknlists.h>
#include <aknpopup.h>
#include <BADESCA.H>
 
Link Against:
avkon.lib
eikctl.lib
eikcoctl.lib
bafl.lib



_LIT(KtxPopUpTitle            ,"Select item");
 
_LIT(KtxPopUpItem1            ,"Item 1");
_LIT(KtxPopUpItem2            ,"Item 2");
_LIT(KtxPopUpItem3            ,"Item 3");
_LIT(KtxPopUpItem4            ,"Item 4");
_LIT(KtxPopUpItem5            ,"Item 5");
 
void SelectSomethingL(TDes& aSelected)
{
    CAknSinglePopupMenuStyleListBox* list =
new(ELeave)CAknSinglePopupMenuStyleListBox;
    CleanupStack::PushL(list);
 
    CAknPopupList* popupList = CAknPopupList::NewL(list,
R_AVKON_SOFTKEYS_OK_BACK, AknPopupLayouts::EMenuWindow); 
    CleanupStack::PushL(popupList);
 
    list->ConstructL(popupList, 0);
    list->CreateScrollBarFrameL(ETrue);
    list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
CEikScrollBarFrame::EAuto);
 
    CDesCArrayFlat* ItemArray = new(ELeave)CDesCArrayFlat(5);
    CleanupStack::PushL(ItemArray);
 
    // add the item adding in here..
    ItemArray->AppendL(KtxPopUpItem1);
    ItemArray->AppendL(KtxPopUpItem2);
    ItemArray->AppendL(KtxPopUpItem3);
    ItemArray->AppendL(KtxPopUpItem4);
    ItemArray->AppendL(KtxPopUpItem5);
 
    CleanupStack::Pop();            //ItemArray
    list->Model()->SetItemTextArray(ItemArray);
    list->Model()->SetOwnershipType(ELbmOwnsItemArray);
 
    popupList->SetTitleL(KtxPopUpTitle);
 
    // Show popup list and then show return value.
    TInt popupOk = popupList->ExecuteLD();
    if (popupOk)
    {
        TInt Sel = list->CurrentItemIndex();
        if (Sel >= 0 && Sel < ItemArray->MdcaCount())
        {
            aSelected.Copy(ItemArray->MdcaPoint(Sel));
        }
    }
 
    CleanupStack::Pop();            // popuplist
    CleanupStack::PopAndDestroy(1); // list
}

你可能感兴趣的:(从下边弹出一个列表实现单选)