I am subclassing the ImageView class and adding to the Gallery View.
But, nothing seems to get drawn in the expected location; though I can
fling through the Gallery list. I added an image from a resource, and
it shows up correctly in the Gallery.

Any idea on why this may be happening?

Here is the code I am using:
public class CustomCanvas extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Gallery g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));
    }

    private class CustomImageView extends ImageView {

        public CustomImageView(Context context) {
                this(context, null);
        }

        public CustomImageView(Context context, AttributeSet attrs) {
                this(context, attrs, 0);
        }

        public CustomImageView(Context context, AttributeSet attrs, int
defStyle) {
                super(context, attrs, defStyle);
        }

        protected void onDraw(Canvas canvas)
        {
            canvas.drawColor(Color.BLUE);
        }

    }

    private class ImageAdapter extends BaseAdapter{

        public ImageAdapter(Context c) {
            mContext = c;
        }

                public int getCount() {
                        return 2;
                }

                public Object getItem(int position) {
                        return position;
                }

                public long getItemId(int position) {
                        return position;
                }

                public View getView(int position, View convertView, ViewGroup
parent) {

                if (position == 1)
                {
                    ImageView i = new ImageView(mContext);
                i.setImageResource(R.drawable.icon);
                return i;
                }
                else
                {
                        CustomImageView w = new CustomImageView(mContext);
                        w.invalidate();
                        return w;
                }
        }

                 private Context mContext;

    }

}

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

Reply via email to