I am new to Java and Android. I have a piece of code that is used for several actions, so I moved it to my own .java library file. However, now my findViewById returns null, where they used to return the material when they were part of the main Activity file with onCreate () and setContentView () calls. How to make it work inside my library?
A call from the Activity class:
helper.popupControl (getListView (), getBaseContext (), "on");
Code in libral:
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(); } } }
source share