android fragment 接受接口回调

第一种

public void onAttach(Context context) {
        super.onAttach(context);

       try {
            mListener = (SingleOptionsPicker.onListener) context;
          mListener.OnListener();
        }catch (ClassCastException e) {
            throw new ClassCastException(context.toString()
                    + " must implement SingleOptionsPicker.onListener");

    }

第二种

      @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            OnListener listener = (OnListener) activity;
        }
或是
        @Override
        public void onAttach(Context context) {
            OnListener listener = (OnListener) activity;
        }

都不行
如何解决接受接口回调

回调不应该这种方式,而是传自身实例过去回调回来