How to change the views (handling back key)

Login to reply to this topic.
Thu, 2007-12-27 10:22
Joined: 2007-12-27
Forum posts: 2

Hi,
In my module i have two views
ContactsSetting view
Photosetting view
these two views can be launched from any other views.
Now i want to implement back key funtionality to this views. when i press back key option in this current view it should go back to previous view from where this setting view was called. Can anyone please tell me how to implement this??


Thu, 2008-01-10 07:37
Joined: 2007-07-24
Forum posts: 55
Re: How to change the views (handling back key)

hi nagesh,
Before going to next view u just implement this and u can set command as per ur needy.
CEikButtonGroupContainer* cba1=CEikButtonGroupContainer::Current();
cba1->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
cba1->DrawNow();
Thanks
mitu

Thu, 2008-01-10 09:20
Joined: 2007-12-27
Forum posts: 2
Re: How to change the views (handling back key)

Hi,
This will change the options sofkeys which ever way needed. but how this will handle back key. when you press back key you would't be knowing the view from which we have come from.Does this CEikButtonGroupContainer::Current(); map the back key to the previous view. pls explain.

regards
Nagesh N

Thu, 2008-01-10 10:51
Joined: 2007-07-24
Forum posts: 55
Re: How to change the views (handling back key)

Hi nagesh,
In HandleCommandL method u take this case
case EAknSoftkeyBack:
in this method u make comparision .if view2 then go to view1(when click back option in view2) and also vice versa.while creating view u should take any flag and which ensure to comparison between views.
Thanks
mitu

Sun, 2008-02-03 22:48
Joined: 2006-10-06
Forum posts: 8
Re: How to change the views (handling back key)

Make CMyViewBase, e.g.

class CMyViewBase : public CCoeControl, public MCoeView {
...
        TVwsViewId ViewId() const
        {
                return TVwsViewId(SbiUid, ViewUid());
        }

        virtual TUid ViewUid() const = 0;  // implemened in derived class
...
}

Then all your views (ContactsSetting, PhotoSetting) will be inhertited from CMyViewBase.

In Your CAknAppaUI use array of all created views (fill this array e.g. in ctor of CAknAppUI)

class CMyAppUI ... {

        CMyViewBase* iViews[MAX_VIEWS];
        CMyViewBase* iPreviousView;

        CMyAppUI {
                // create views here, and store pointers into array iViews
        }

        void HandleCommandL(TInt aCommand) {
                ...
                switch (aCommand) {
                case EAknSoftkeyExit: {
                        Exit();
                }
                case EAknSoftkeyBack: {
                        // use SwitchViewL here to navigate between your views. You can use
                        // CurrentView() and/or iPreviousView
                }
                ....
         }

        void SwitchViewL(const TUid& aTargetViewId, CMyViewBase& aTargetView) {
                if ( CurrentView()!= &aTargetView) {
                        TVwsViewId id(MyUid, aTargetViewId);
                        ActivateViewL(id);
                }
        }

        CMyViewBase* CurrentView() {
                TVwsViewId id;
                TInt err = GetActiveViewId(id);
                if ( err == KErrNone) {
                        for (TInt i = 0; i < MAX_VIEWS; i++) {
                                if ( iViews[i] && id == iViews[i]->ViewId()) {
                                        return iViews[i];
                                }
                        }
                }
                return NULL;
        }

}


Jozef Prídavok - http://pridavok.sk/
Mothiva, s.r.o - http://mothiva.com/

  • Login to reply to this topic.