The following example shows how to update the CBA of a custom dialog depending upon a given conditon. There are lot of times when we want to bring up a dialog and then change the CBA depending upon certain conditons, i.e. text inputted in the dialog/state of the application etc.
Header file required:
#include <aknquerydialog.h>
No rss is provided as the standard rss for a query dialog would work fine.
Add following lines in .h file.
class CYourDialog : public CAknTextQueryDialog
{
public:
static CYourDialog* NewL(
TDes& aText, TTone aTone = ENoTone)
{
CYourDialog* self =
new (ELeave) CYourDialog(aText, aTone);
return self;
}
protected:
CYourDialog(TDes& aText, const TTone& aTone):CAknTextQueryDialog(aText, aTone)
{
// No implementation required
}
protected: // from CAknTextQueryDialog
void UpdateLeftSoftKeyL(); //This function would be called everytime something is entered in the dialog
};
Add following lines in .cpp file.
// In your container/view class
TBuf<20> myText;
iYourDialog = CYourDialog::NewL(myText);
iYourDialog->PrepareLC(/*Resource def from rssi file*/);
iYourDialog->RunLD();
/**
* Over-ridden function from CAknTextQueryDialog, allows us to change the
* text of the LSK depending on some condition
*/
void CYourDialog::UpdateLeftSoftKeyL()
{
CEikButtonGroupContainer& cba = ButtonGroupContainer();
cba.SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL);
TInt posOk = cba.PositionById(EAknSoftkeyOk);
HBufC* textResource = NULL;
MakeLeftSoftkeyVisible(ETrue); //Even if there is nothing, shows the LSK
if(CheckIfEntryTextOk()) // in case something is entered
{
if(/*Your Condition 1*/)
{
// My Condition 1 met, leme update
textResource = StringLoader::LoadLC(/*Text resource from rss*/);
cba.SetCommandL(posOk, EAknSoftkeyOk, *textResource);
}
else if(/*Your Condition 2*/)
{
// My Condition 2 met, leme update
textResource = StringLoader::LoadLC(/*Text resource from rss*/);
cba.SetCommandL(posOk, EAknSoftkeyOk, *textResource);
}
}
else
{
// No text is there, lets put something else
textResource = StringLoader::LoadLC(/*Text resource from rss*/);
cba.SetCommandL(posOk, EAknSoftkeyOk, *textResource);
}
if(textResource != NULL)
{
CleanupStack::PopAndDestroy( textResource );
cba.DrawNow();
}
}
Now with this code, your RSK would be changed to show something else depending on what you want instead of the simple Ok which could be confusing to the user on conditional states in your application.
Added by - Mayank on 12/05/2009
No related wiki articles found