Skip to content Skip to sidebar Skip to footer

How To Get A View From A Fragment Layout In Android?

I have an xml like this activity_loginscreen.xml

Solution 1:

Make your PlaceholderFragment fragment onCreateView(....) like

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Viewview= inflater.inflate(R.layout.gragment_loginscreen, container, false);
    ImageViewbubbles= (ImageView)view.findViewById(R.id.bubbles);
    return view;
}

and used getActivity() as a Context in Fragment like

AnimationanimContentUp= AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up_service);

Solution 2:

Place the imageView in your PlaceholderFragmentonCreateView and in the PlaceholderFragment inflate the layout gragment_loginscreen which will generate a view..

example:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Viewview= inflater.inflate(R.layout.gragment_loginscreen, container, false);
        ImageViewbubbles= (ImageView)view.findViewById(R.id.bubbles);
        return view;
}

Post a Comment for "How To Get A View From A Fragment Layout In Android?"