How to use addView in ViewGroup?
22:53 04 Aug 2011

I wanted to use a ViewGroup class and add views into it. So how can we accomplish this??

Something like this ::

public class DrawView extends View  {  
   private static final String TAG = "DrawView";  
   List points = new ArrayList();  
   Paint paint = new Paint();
   public DrawView(Context context) { //2

        super(context);  
        System.out.println("drawwwwwwwwwwwwwwwwwwwwwconnnnnnnnnnnnn");  

        setFocusable(true);  
        setFocusableInTouchMode(true);  
        paint.setColor(Color.MAGENTA);  
        paint.setAntiAlias(true);  

    }        
    @Override  
    public void onDraw(Canvas canvas) {  
        System.out.println("drawwwwwwwwwwwwwwwwwwwww");  
        for (Point point : points) {  
            canvas.drawCircle(point.x, point.y, 5, paint);  
            // Log.d(TAG, "Painting: "+point);  

         }      
    }  

ViewGrp ::

public class Group extends ViewGroup{  
    DrawView draw;  
    SecondView sec;  
    public Group(Context context) {  
        super(context);  
        // TODO Auto-generated constructor stub  
        draw=new DrawView(getContext());  
        sec=new SecondView(getContext());  
        addView(draw);  
        addView(sec);  
        System.out.println("hellloooooooo"); //4  
    }  

    @Override  
    protected void onLayout(boolean changed, int l, int t, int r, int b) {  
         // TODO Auto-generated method stub  
        System.out.println("hiiiiiiiiii layoutttttttttt"); //6  
    }  


 }  

Main Activity :

 @Override  
     public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        System.out.println("222222222222222222222"); //1  
        grp=new Group(this);  
        setContentView(grp);  
        System.out.println("1111111111111111111"); //5  
    }  

Second view ::

 public class SecondView extends View  {  

     private static final String TAG = "DrawView2";  

    Paint paint = new Paint();  
    public SecondView(Context context) { //3  
        super(context);  
        System.out.println("secccccccccccccccccccccccccccccccconnnnnnnn");  
        setFocusable(true);  
        setFocusableInTouchMode(true);  
        paint.setColor(Color.MAGENTA);  
        paint.setAntiAlias(true);  

   }      
    @Override  
     public void onDraw(Canvas canvas) {  
        canvas.drawColor(Color.BLUE);  
        // Log.d(TAG, "Painting: "+point);  
        System.out.println("seccccccccccccccc1");  
    }      

Please guide me to write the addView in right place

Thanks
sneha

android view