I'm new to Java and Android. I have a piece of code that is used for multiple activities so I moved it into its own library .java file. However, now my findViewById return null where they used to return the right stuff when they were part of the main Activity file with onCreate() and setContentView() calls. How do I make it work inside my library?
Call from the Activity class:
helper.popupControl(getListView(), getBaseContext(), "on");
The code in the libruary:
public class Helper extends ListActivity {
public void popupControl (View v, Context context, String on_off) {
Animation aFilm = AnimationUtils.loadAnimation(context, R.anim.fade_in);
aFilm.reset();
View vFilm = (View) v.findViewById(R.id.gray_out_film);
if(vFilm==null) {
Toast maxToast = Toast.makeText(context, "View is null! "+R.id.gray_out_film+", View:"+v.toString(), Toast.LENGTH_LONG);
maxToast.setGravity(Gravity.CENTER, 0, 0);
maxToast.show();
} else {
Toast maxToast = Toast.makeText(context, "View is not null!", Toast.LENGTH_SHORT);
maxToast.setGravity(Gravity.CENTER, 0, 0);
maxToast.show();
}
}
}