Question

I'm using CameraDemo-Layout as an example for how to properly put buttons on a screen with the camera fragment.

I'm trying to use setCameraView()

  /**
   * Use this if you are overriding onCreateView() and are
   * inflating a layout containing your CameraView, to tell
   * the fragment the CameraView, so the fragment can help
   * manage it. You do not need to call this if you are
   * allowing the fragment to create its own CameraView
   * instance.
   * 
   * @param cameraView
   *          the CameraView from your inflated layout
   */
  protected void setCameraView(CameraView cameraView) {
    this.cameraView=cameraView;
  }

but, I can't use it since it's protected. I'm using the CameraDemo - Layout as an example. I have my own CustomCam, CustomCamFragment, and CustomCamHost.

In CustomCamFragment in onCreateView I'm attempting to use setCameraView, but it is undefined. Was this by mistake or should I follow the rule "You do not need to call this..." because I don't quite understand that part?

Was it helpful?

Solution

but, I can't use it since it's protected

It is designed to be called from a subclass of CameraFragment, and a protected method is available to subclasses.

I'm using the CameraDemo - Layout as an example

And you can see a call to setCameraView() in onCreateView() of the DemoCameraFragment in that sample:

  @Override
  public View onCreateView(LayoutInflater inflater,
                           ViewGroup container,
                           Bundle savedInstanceState) {
    View content=inflater.inflate(R.layout.camera, container, false);
    CameraView cameraView=(CameraView)content.findViewById(R.id.camera);

    setCameraView(cameraView);

    return(content);
  }

should I follow the rule "You do not need to call this..." because I don't quite understand that part?

Either you are creating an instance of a CameraView yourself (via a constructor or layout inflation), or you are not.

If you are creating such an instance, and you want to use a CameraFragment subclass, that subclass must call setCameraView(), passing in the CameraView instance.

If you are not creating such an instance, instead allowing the stock implementation of CameraFragment to create a CameraView for you, you do not need to call setCameraView(), in part because you do not have a CameraView to set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top