I've got a main class and a second class that handles an object within the main class. The second class needs to manipulate the layout of the main class (changing background images of objects), but the findViewById() function is returning null every time. The second class isn't a new Activity (at least, I don't think it should be), so I'm pretty sure I don't want to call setContentView(R.layout.main) in the second class, since the main class is an activity with that View.
Here's what I have:
- Code: Select all
public class MainClass extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SubClass item = new SubClass(this);
}
}
And then the other class is:
- Code: Select all
public class Dice extends View {
public Dice(Context context){
super(context);
img1 = (ImageView)findViewById(R.id.img1);
}
}
There is more to the code, but these are the relevant bits. The img1 is always null, no matter what I do.
Ideas?


