I\'m trying to create a simple fragment that merely displays an image when clicked. I\'m getting numerous errors inlcuding \"the method findViewbyId(int) is undefined for the ty
findViewById is a method in the class Activity. To avoid passing an instance of the entire activity use a WeakRefence (see http://developer.android.com/reference/java/lang/ref/WeakReference.html) for example
private WeakReference activity;
public ExampleFragment(MainActivity mainActivity) {
activity = new WeakReference(mainActivity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ImageView imageview = (ImageView)activity.findViewById(R.id.imageView1);
return Inflater.inflate(R.layout.iamgeview_main, container, false);
}