listbox problem
| Tue, 2005-11-22 01:26 | |
|
Hi,
I have a strange problem with my listbox... I have a function createList which does everything for the creation of the list. If I call this function in the ConstructL function of my container class, it works fine. But if I call it anywhere else it doesn't work, it compiles, but then exits at run time (breaks in debug mode of visual studio). I want to call this function from the AppUi class as I want the list to be displayed after a key press. Is this possible? Thanks, Miranda |
|






Forum posts: 1242
Maybe you show the relevant parts of the code here so it will be possible to see more details? Do you know *where* it leaves?
René Brunner
Forum posts: 70
The list box I am creating is a list of the images or sounds in the users gallery.
here is the code that works:
ConstructL
  {
  CreateWindowL();
   phase = 0;
   iSplashImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename, EMbmSmilimagesSplash);
   createList();
  SetRect(aRect);
  ActivateL();
  }
createList
{
RDebug::Print(_L("createList"));
User::LeaveIfError(aFs.Connect());
User::LeaveIfError(aFs.GetDir(KDirSounds, KEntryAttNormal, ESortByName, dir));
if ( iList )
{
delete iList;
iList = NULL;
}
// listbox instance
iList = new (ELeave) CAknSingleStyleListBox();
iList->SetContainerWindowL(*this);
iList->ConstructL(this,EAknListBoxSelectionList);
//iList->CreateScrollBarFrameL(ETrue);
//iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
iList->CreateScrollBarFrameL(ETrue);
iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iList->Model()->SetOwnershipType(ELbmOwnsItemArray);
iList->ActivateL();
//Fill list box with the data
CDesCArray *itemList = new (ELeave) CDesCArrayFlat(8);
if(!dir)
    return;
           Â
  for (TInt i=0;i<dir->Count();i++)
    {
    TFileName filename = NULL;
    if(iSizeDate==1)
      {
      // Show file size
      filename.Format(KStringSize,i+1,&(*dir)[i].iName,(*dir)[i].iSize);
      }
    else
      {
      // Fix the date and time string of last modification
      TBuf<30> dateString;
      _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
      (*dir)[i].iModified.FormatL(dateString,KDateString);
      // Show date modified
      filename.Format(KStringDate,i+1,&(*dir)[i].iName,&dateString);
      }
    itemList->AppendL(filename);
    }
// set items and ownership
iList->Model()->SetItemTextArray(itemList);
iList->Model()->SetOwnershipType(ELbmOwnsItemArray);
iList->CreateScrollBarFrameL(ETrue);
iList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
iList->HandleItemAdditionL();
  iList->SetCurrentItemIndex(0);
iList->SetFocus(ETrue);
iCtrlArray.Append( iList );
iList->DrawNow();
iList->SetListBoxObserver(this);
iList->SetObserver(this);
aFs.Close();
}
So what I want to do is call createList from AppUi like this:
  {
if (aType == EEventKey) {
switch (aKeyEvent.iScanCode)
{
case (57):
{
Exit();
break;
}
case EStdKeyDevice3:
{
RDebug::Print(_L("ok key pressed"));
iAppContainer->phase = 1;
iAppContainer->DrawNow();
iAppContainer->createList();
return EKeyWasConsumed;
}
}
}
  return EKeyWasNotConsumed;
  }
it appears to leave at the sizeChanged function, but I recall when I was first having listbox problems I got a similar leave that had nothing to do with setExtent...
Any ideas?
Forum posts: 1242
Concretely: Move the following lines that configure the listbox:
iList->SetObserver(this);
Delete the line
Likewise, in HandleKeyEventL, call createList first, only then call the DrawNow method.
The general idea behind my proposals is the following: Maybe Symbian internally gets confused if one starts to "use" a listbox, e.g. set items and asks them to be drawn, when the listbox is only partially configured or if certain aspects (like observers) of the listbox are changed while some background task is still busy drawing the new items.
But anyway, just my guessesÂ
René Brunner
Forum posts: 70
Any other ideas?
Forum posts: 1242
E.g. move it up in the procedure together with two lines that set the observers. Who knows how early there will be calls to the procedures of your container handling the different objects, and maybe a chance for confusion if the listbox appears too late in the list.
But if that does not help either, I have to capitulate...
René Brunner
Forum posts: 1242
Maybe you will have to separate creating the listbox and filling it. Create it in the ConstructL method, what will work according to your report, but leave it empty. Later on, after the keypress, fill it.
Isn't there a way to make (existing) controls visible and invisible so that you could create the listbox, but leave it invisible until the keypress and make it visible only after it is filled? Check the method CCoeControl::MakeVisible!
René Brunner