To be able to receive toolbar item events in your application or application view, you must implement the toolbar observer interface in the view and register the view to the toolbar:
To receive toolbar item
events, use the observer class MAknToolbarObserver
.
The example below shows how to set the toolbar observer.
void CMyAppView::ConstructL( TInt aResId ) { BaseConstructL( aResId ); CAknToolbar* toolbar = Toolbar(); if ( toolbar ) { toolbar->SetToolbarObserver( this ); } }
Handle toolbar item events in MAknToolbarObserver
’s OfferToolbarEventL()
.
OfferToolbarEventL()
is called when the toolbar item state
has changed, for example when a button is pressed. When handling a
toolbar event, the control in question can be identified from the
commandid that is sent as a parameter in the method. The ID belongs
to that control it was sent from (in case of a button, the ID of the
button that was pressed).
The example below illustrates
how to implement OfferToolBarEventL()
.
void CMyAppView::OfferToolbarEventL( TInt aCommandId ) { if ( aCommandId == KButtonId ) { // do button function … } }