创建一个弹出式的模态列表: void CContAppUi::ShowMobilePopListL() { CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox; CleanupStack::PushL(list); // Create popup list and PUSH it. CAknPopupList* popupList = CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_MENU_LIST, AknPopupLayouts::EMenuWindow); CleanupStack::PushL(popupList); // initialize listbox. list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect); list->CreateScrollBarFrameL(ETrue); list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); MDesCArray* itemList = list->Model()->ItemTextArray(); CDesCArray* items = (CDesCArray*) itemList; FillList(items); popupList->SetTitleL(_L("Title of the dialog")); // Show popup list and then show return value. TInt popupOk = popupList->ExecuteLD(); //If the user enters ok on a selection if (popupOk) { //Do what you have to do TInt index = list->CurrentItemIndex(); TBuf<KMessageLength> msg; /** TBuf<KMessageLength> format; iCoeEnv->ReadResource( format, R_AKNEXPOPLIST_SELECT_MESSAGE ); */ _LIT(format,"Item %d was selected."); msg.Format( format, index + 1 ); CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog( CAknNoteDialog::ENoTone, CAknNoteDialog::ENoTimeout ); dlg->PrepareLC( R_AKNEXPOPLIST_SELECT_MESSAGE_NOTE ); dlg->SetTextPluralityL( EFalse ); dlg->SetTextL( msg ); dlg->RunLD(); } CleanupStack::Pop(); CleanupStack::PopAndDestroy(); } void CContAppUi::FillList(CDesCArray* items) { items->AppendL(_L("test1")); items->AppendL(_L("test2")); items->AppendL(_L("test3")); items->AppendL(_L("test4")); items->AppendL(_L("test5")); } |