Recently, I have read a list of multi-view settings in some programs. I learned how to implement it and recorded it briefly to avoid future reference. The main functions are as follows:
Main Program Interface
Select Settings in the menu
Open settings view 1
Open settings view 2
1. The UI class inherits from the makntabobserver class and implements its void tabchangedl (tint aindex); function (for detailed implementation, see below ).
2. Define the pointer of the navigation indicator in the UI class
Caknnavigationdecorator * inavidecorator;
3. Implement the following in the UI function:
Void cs60uiexampleappui: handlecommandl (tint acommand)
{
Switch (acommand)
{
Case eeikcmdexit:
Case eaknsoftkeyexit:
Exit ();
Break;
// Select the settings menu
Case es60uiexamplesettings:
{
Tuid navipaneuid;
Navipaneuid. iuid = eeikstatuspaneuidnavi;
Ceikstatuspane * statuspane = statuspane ();
Ceikstatuspanebase: tpanecapabilities subpane =
Statuspane-> panecapabilities (navipaneuid );
// If we can access the Navigation Pane
If (subpane. ispresent () & subpane. isappowned ())
{
Caknnavigationcontrolcontainer * navipane =
(Caknnavigationcontrolcontainer *) statuspane-> controll (navipaneuid );
Delete inavidecorator;
Inavidecorator = NULL;
// Ownership is transferred to us here
Inavidecorator = navipane-> createtabgroupl ();
// Ownership not transferred
Cakntabgroup * tabgroup = (cakntabgroup *) inavidecorator-> decoratedcontrol ();
// Display two tabs of normal length on the Navigation Pane at a time
Tabgroup-> settabfixedwidthl (ktabwidthwithonetab); // you can specify whether one or more labels are displayed in the View bar.
Tabgroup-> setobserver (this );
// Add two views and titles to be displayed. You can also add multiple
Hbufc * tab1text = stringloader: loadlc (r_s60uiexample_highscore_title_text );
Tabgroup-> addtabl (es60uiexamplesettingsviewid1, * tab1text );
Cleanupstack: popanddestroy (tab1text );
Hbufc * tab2text = stringloader: loadlc (r_s60uiexample_resetting_text );
Tabgroup-> addtabl (es60uiexamplesettingsviewid2, * tab2text );
Cleanupstack: popanddestroy (tab2text );
// Highlight the first tab
Tabgroup-> setactivetabbyindex (0 );
Navipane-> pushl (* inavidecorator );
// Activate the first view
Activatelocalviewl (tuid: UID (tabgroup-> tabidfromindex (0 )));
}
Break;
}
// Destroy the navigation bar when the returned view is set
Case es60uiexampledelnavi:
{
Tuid navipaneuid;
Navipaneuid. iuid = eeikstatuspaneuidnavi;
Ceikstatuspane * statuspane = statuspane ();
Ceikstatuspanebase: tpanecapabilities subpane =
Statuspane-> panecapabilities (navipaneuid );
// If we can access the Navigation Pane
If (subpane. ispresent () & subpane. isappowned ())
{
Caknnavigationcontrolcontainer * navipane =
(Caknnavigationcontrolcontainer *) statuspane-> controll (navipaneuid );
Delete inavidecorator;
Inavidecorator = NULL;
Navipane-> pushdefaultl ();
}
Break;
}
Default:
Panic (es60uiexamplebasicui );
Break;
}
}
// Response from the acceptance button in the navigation bar
Tkeyresponse cs60uiexampleappui: handlekeyeventl (const tkeyevent & akeyevent, teventcode Atype)
{
If (inavidecorator = NULL)
{
Return ekeywasnotconsumed;
}
Cakntabgroup * tabgroup = (cakntabgroup *) inavidecorator-> decoratedcontrol ();
If (tabgroup = NULL)
{
Return ekeywasnotconsumed;
}
// If we 've got a tab group, then offer the key event to it.
Return tabgroup-> offerkeyeventl (akeyevent, Atype );
}
// Display different views based on the buttons
Void cs60uiexampleappui: tabchangedl (tint aindex)
{
If (inavidecorator! = NULL)
{
Cakntabgroup * tabgroup = (cakntabgroup *) inavidecorator-> decoratedcontrol ();
Activatelocalviewl (tuid: UID (tabgroup-> tabidfromindex (aindex )));
}
}
// Delete the corresponding navigation bar indicator from the UI class destructor
Cs60uiexampleappui ::~ Cs60uiexampleappui ()
{
Delete inavidecorator;
Inavidecorator = NULL;
}
4. Implement the offerkeyeventl function in the settings list class from caknsettingitemlist to avoid left and right navigation failures.
Tkeyresponse cs60uiexamplelist: offerkeyeventl (const tkeyevent & akeyevent, teventcode Atype)
{
If (Atype! = Eeventkey) // is not key event?
{
Return ekeywasnotconsumed;
}
Switch (akeyevent. icode)
{
Case ekeyleftarrow:
Case ekeyrightarrow:
Return ekeywasnotconsumed;
Break;
Default:
Break;
}
}
5. Destroy the navigation indicator created in the UI when pressing the return button in the View class of each setting list
Void cs60uiexamplesettingsview: handlecommandl (tint acommand)
Add the following code to the function:
Case eaknsoftkeyback:
{
Appui ()-> handlecommandl (es60uiexampledelnavi );
Appui ()-> activatelocalviewl (tuid: UID (es60uiexampleinitialviewid ));
Break;
}