Hello,
        I want to define the custom View, draw it by myself and use it
in the BaseAdapter's getView() method.
I have overwritted the onDraw(), but the onDraw() method isn't called
and nothing displayed. I don't know why.
Appreciate any advice and help. The code is as follow:

public class VideoItemByDraw extends View {

        private TVVideo mVideo = null;

        public VideoItemByDraw(Context context) {
                super(context);
                // TODO Auto-generated constructor stub
        }

        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
                canvas.drawColor(Color.GRAY);
                Paint paint = new Paint();
                paint.setAntiAlias(true);
                paint.setColor(Color.BLACK);
                if(mVideo==null)
                        return;
                // draw the video title
                paint.setTextSize(16);
                canvas.drawText(mVideo.get_title(), 95, 10, paint);
                // draw the video date
                paint.setTextSize(12);
                canvas.drawText(mVideo.get_uploadTime(), 95, 28, paint);
                // draw the video duration
                canvas.drawText(mVideo.get_duration(), 95, 42, paint);
                // draw the video viewTimes
                canvas.drawText(mVideo.get_viewTimes(), 95, 56, paint);
                //draw the video grade
                
canvas.drawText(this.getResources().getString(R.string.video_grade),
95, 70, paint);
                int grade = Integer.valueOf(mVideo.get_grade());
                int scaleX = 20;
                for(int i=0;i<grade;i++){
                        Drawable drawable = this.getResources().getDrawable
(R.drawable.star_bright);
                        drawable.setBounds(95+scaleX, 70, 95+scaleX, 80);
                        drawable.draw(canvas);
                        scaleX+=10;
                }
        }
        /**
         * set the video and update the video item
         * @param video The video info object
         */
        public void setVideo(TVVideo video){
                this.mVideo = video;
                this.invalidate();
        }


}

the getView() is as follow:

        public View getView(int position, View convertView, ViewGroup parent)
{
                // TODO Auto-generated method stub
                TVVideo video = mVideoInfo.getVideoByIndex(position);
                if(convertView != null){
                        ((VideoItemByDraw)convertView).setVideo(video);
                        return convertView;
                }
                VideoItemByDraw videoItem = new VideoItemByDraw(mContext);
                videoItem.setVideo(video);
                return videoItem;
        }

Thanks for any help.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to