Android: how to notify Activity when Fragments views are ready?

前端 未结 4 863
陌清茗
陌清茗 2020-12-14 07:34

I\'m using Google Maps API V2 in an activity wih drop down navigation where the map is on the second position.

I\'m adding the map pragmatically like:



        
4条回答
  •  被撕碎了的回忆
    2020-12-14 07:59

    In addition to Kirk's answer: since public void onAttach(Activity activity) is deprecated you can now simply use:

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    
        Activity activity;
    
        if (context instanceof Activity){
    
            activity=(Activity) context;
    
            try {
                this.mListener = (OnCompleteListener)activity;
            } catch (final ClassCastException e) {
                throw new ClassCastException(activity.toString() + " must implement OnCompleteListener");
            }
        }
    }
    

    The rest remains the same... One might want to use (Fragment sender) as a parameter though and always pass this.

提交回复
热议问题