Code example for ImageButton

Methods: setAdjustViewBoundssetImageResourcesetScaleType, setBackgroundDrawable, setClickable, setFocusable, setLayoutParams, setPadding

0
        public View getView(int position, View convertView, ViewGroup parent)
        { 
            ImageButton imageButton;
            if (convertView == null)
            {  // if it's not recycled, initialize some attributes 
                imageButton = new ImageButton(mContext);
                imageButton.setLayoutParams(new GridView.LayoutParams(150,150));
                imageButton.setScaleType(ImageButton.ScaleType.CENTER_CROP);
                imageButton.setPadding(7, 8, 7, 8);
                imageButton.setAdjustViewBounds(true);
 
                Drawable d;
                d = Drawable.createFromPath(mThumbIds[position].toString());
                imageButton.setBackgroundDrawable(d);
            } 
            else 
            { 
                imageButton = (ImageButton) convertView;
            } 
 
            imageButton.setImageResource(mThumbIds[position]);
             
            //------------------------------ 
            //NB !!! 
            // Add this to the imageButton 
            // because when you click on 
            // the button , you will actually 
            // need to click on the gridview 
            // and NOT the button. If you 
            // dont do this , you wont be  
            // able to click on the "button" 
            // part of the gridview and the 
            // click event wont launch. 
            // - Gid 
            //------------------------------ 
            imageButton.setFocusable(false);
            imageButton.setClickable(false);
            //------------------------------ 
 
            return imageButton;
        } 
        //----------------------------------------