开发者

onDraw, onmeasure does not gets called

I have a LinearLayout which has a gridview:

public class ParentClass implements OnClickListener , OnFocusChangeListener
{

//instance variables.
//constru开发者_运维问答ctors.
//initialization method:

public initMethod()
 {
  //initializes gridview , set adapters, listeners etc.
  //+ code for adding gridview to linear layout etc.
 }
//other methods
...
}
class Grid extends ViewGroup{

        private GridView _gridView = null;      
        Grid()
        {
        super(MyActivity);
        //code for grid-view initialization goes here
        }

        public void setAdapter(GridViewAdapter gridViewAdapter) {
            // TODO Auto-generated method stub
            _gridView.setAdapter(gridViewAdapter);

        }

        @Override
         protected void onDraw(android.graphics.Canvas canvas) {
             super.onDraw(canvas);


         }
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            // TODO Auto-generated method stub
            int i = 0;
        }
    }
}

Now i expect that when i put a breakpint in overridden methods of my Grid class, it should hit! Why Breakpoint does not get hit? Am i missing something fundamental here?


As per question comments, Grid was instantiated but not added to the layout, therefore it never formed part of your View hierarchy, and so nothing would call it's onLayout() etc.

A contained GridView instance, referenced in Grid._gridView, did get added to the layout, hence the confusion.

Possibly the Grid class should be extending GridView rather than containing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜