Skip to content Skip to sidebar Skip to footer

Android Get View Of Fragment In Activity

I have an activity, let's call it A, and it launches a fragment like so: remoteFragment = new RemoteFragment(); getSupportFragmentManager() .beginTransaction() .rep

Solution 1:

Here, you are trying to find the view from layoutOnTopScrollview. Instead you should find the okBtn from inflated view. Please change code as below:

@Overridepublic View onCreateView(LayoutInflater inflater, final ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragmentViewview= inflater.inflate(R.layout.fragment_remote, container, false);
    okBtn= view.findViewById(R.id.okBtn);

    return view;
}

Also, make sure that you are calling this method once the fragment is created.

Post a Comment for "Android Get View Of Fragment In Activity"