5

I found examples for the legacy version, but not for the new builder pattern. Does anyone know how to do this?

1 Answer 1

13

The Builder constructor only needs an activity public Builder(Activity activity) so:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment, container, false);
    showcaseView = new ShowcaseView.Builder(getActivity())
            .setTarget(new ViewTarget(view.findViewById(R.id.textView)))
            .setOnClickListener(listener)
            .build();
    ....
3
  • 1
    This would work for an activity, but not for a fragment... I can only getActivity() in onActivityCreated(), but there I can't findViewById() (the views aren't measured yet so I'll get an exception java.lang.IllegalArgumentException: width and height must be > 0). May 22, 2014 at 11:54
  • 3
    @MichaelLitvin that's why you have to do it in the onCreateView method. I just updated my answer.
    – Stephan
    May 22, 2014 at 11:59
  • 1
    Thanks guys, I'll update the sample and example code to show how to do this for other users! May 22, 2014 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.