I have the following View and TextView, How can I add the TextView to the View as it’s child ?
public class MyView extends View {
public MyView(Context context, AttributeSet attrs) {
super(context);
TextView textView = new TextView(context);
textView.setText("Hello My Friends");
}
}
Thanks!
Instead of
ViewuseViewGroupto extend yourCustomViewclass..A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers.
Something Like,
Now, you can use method called
Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.