I have the following problem: I want to add a custom view (custom_view.xml and associated CustomView.java class) to my main activity.
So, I do the following:
1) In my main activity (linked to main.xml):
CustomView customView = new CustomView(this);
mainView.addView(customView);
2) In my CustomView.java class (that I want to link to custom_view.xml):
public class CustomView extends View {
public CustomView(Context context)
{
super(context);
/* setContentView(R.layout.custom_view); This doesn't work here as I am in a class extending from and not from Activity */
TextView aTextView = (TextView) findViewById(R.id.aTextView); // returns null
///etc....
}
}
My problem is that aTextView remains equal to null... It seems clearly due to the fact that my custom_view.xml is not linked to my CustomView.java class. How can I do this link ? Indeed, I tried setContentView(R.layout.custom_view); but it doesn't work (compilation error) as my class extends from View class and not Activity class.
Thanks for your help !!