By Alvin Alexander. Last updated: June 6, 2016
This Java code shows how to implement a couple of things in an onCreateView
method inside a Fragment
class:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); View rootView = inflater.inflate(R.layout.fragment_single_image, parent, false); ImageView imageView = (ImageView)rootView.findViewById(R.id.currentImage); imageView.setImageBitmap(currentImage); return rootView; }
What I’m doing here is:
- Enabling the Android Back/Up button in the
ActionBar
- Getting a reference to the “root view” in my layout file
- Getting a reference to an
ImageView
that I know is in that layout file - Setting a bitmap image on that
ImageView
If you wanted to see how to do any of these things in a fragment’s onCreateView
method, I hope this source code is helpful.