

Without Fragments components, the normal activity class causes running activities to be stopped, reloaded and re-rendered using the new parameters. As a result, web-pages load comparatively faster because it retains their previous state. tOnClickListener(new View.Fragment is a concept of UI components-with a new idea for the ability to retain state across configuration changes. ImageView maps = (ImageView) myFragmentView.findViewById(R.id.ivcityhallmaps) View myFragmentView = inflater.inflate(R.ag_cityhall, container, false) Public class FragCityhall extends Fragment View onCreateView(LayoutInflater inflater, ViewGroup container, the Intent within your Fragment inflation. The solution is to put your widget reference with small adjustment (myFragmentView.findViewbyId) together with e.g. In my example I use an ImageView with an OnClicklistener launching a browser website.

It took me a few hours to actually solve this, and I couldn’t find many resources online, so I would share the solution in this small blog post. Changing your extend to Activity would not solve it ) Button btn = (Button)findViewById(R.id.btn1) When you try this implementation you wil notice that the Android SDK wont recognize your code, this is because you extended Fragments instead of Activity.

This implies that your standard way of referring to android widgets won’t work e.g. Fragments in android don’t extend Activity but Fragment. A quick post on how to add and set android widget behavior in a fragment implementation.
