Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add findViewById in fragment method of library #57

Closed
fabian7593 opened this issue Apr 25, 2017 · 3 comments
Closed

Add findViewById in fragment method of library #57

fabian7593 opened this issue Apr 25, 2017 · 3 comments

Comments

@fabian7593
Copy link

fabian7593 commented Apr 25, 2017

Hello, I want to call the findViewById of an UI Component of my fragment xml...
But the tutorialOptions instance return getActivity and getView in null...
And I dont have the possibillity of call the findViewById.
If you need more information for understand the problem please tell me...

I hope that you can help me.

Thanks.

Example

 public void replaceTutorialFragment() {
        final IndicatorOptions indicatorOptions = IndicatorOptions.newBuilder(this)
                .build();
        final TutorialOptions tutorialOptions = TutorialFragment.newTutorialOptionsBuilder(this)
                .setUseAutoRemoveTutorialFragment(true)
                .setUseInfiniteScroll(true)
                .setPagesColors(mPagesColors)
                .setPagesCount(TOTAL_PAGES)
                .setIndicatorOptions(indicatorOptions)
                .setTutorialPageProvider(new TutorialPagesProvider())
                .setOnSkipClickListener(new OnSkipClickListener(this))
                .build();
        final TutorialFragment tutorialFragment = TutorialFragment.newInstance(tutorialOptions);
        getFragmentManager()
                .beginTransaction()
                .replace(R.id.container, tutorialFragment)
                .commit();



//This is the test, but tutorialOptions return any options in null
(ImageView) imgView = (ImageView)tutorialOptions.getActivity().findViewById(R.id.img_view_test);

if(imgView != null){

} 
}
@fabian7593 fabian7593 changed the title Assign findViewById in fragment method of library Add findViewById in fragment method of library Apr 26, 2017
@Iojjj
Copy link
Contributor

Iojjj commented Apr 26, 2017

You should learn basics of using of fragments. When you call getFragmentManager().commit(), it posts operation to queue so fragment will be added to screen asynchronously. When you then try to find an image view, it's not added to view hierarchy yet. See Javadoc of commit method:

Schedules a commit of this transaction. The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.

But you can use commitNow method instead.

Also note:

  1. Do not ever use views from fragments in other Android components (i.e. activities, other fragments). Only fragment that displays that view must find and use it. So if you need to interact with image view, do it in the fragment.
  2. TutorialOptions instance used by this library's internal components. You don't need to use it at all. Just construct it and pass to TutorialFragment.

@Iojjj
Copy link
Contributor

Iojjj commented Apr 26, 2017

According to the title of this issue Add findViewById in fragment method of library:

It's you who decide which fragments to use. If you need to interact with views of your fragment, then create your own fragment and extend it from PageFragment. There you can manipulate fragment's views. Then you should use TutorialPageProvider instead TutorialPageOptionsProvider. See Configure Tutorial Pages: Via TutorialPageProvider.

@fabian7593
Copy link
Author

Thanks for your response, I try to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants