Code example for ViewSwitcher

Methods: addViewgetChildAt, getTag, setDisplayedChild, setPadding, setTag

0
	public View getView(int position, View convertView, ViewGroup parent) {
    	final ViewSwitcher lViewSwitcher;
		String url = mUrls[position];
		ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	lViewSwitcher = new ViewSwitcher(mContext);
			lViewSwitcher.setPadding(0, 0, 0, 0);
			ProgressBar lProgress = new ProgressBar(mContext);
			lProgress.setLayoutParams(new ViewSwitcher.LayoutParams(40, 40));
			lViewSwitcher.addView(lProgress);
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5, 5, 5, 5);
            lViewSwitcher.addView(imageView);
             
            // attach the onclick listener 
			//lViewSwitcher.setOnClickListener(new ClickHandler()); 
        } else { 
        	lViewSwitcher = (ViewSwitcher) convertView;
        } 
         
        ViewTagInformation lTagHolder = (ViewTagInformation) lViewSwitcher
		.getTag();
        if (lTagHolder == null || 
    			!lTagHolder.url.equals(url)) {
    			// The Tagholder is null meaning this is a first time load 
    			// or this view is being recycled with a different image 
    			 
    			// Create a ViewTag to store information for later 
    			ViewTagInformation lNewTag = new ViewTagInformation();
    			lNewTag.url = url;
    			lViewSwitcher.setTag(lNewTag);
 
    			// Grab the image view 
    			// Have the progress bar display 
    			// Then queue the image loading 
    			ImageView lImageView = (ImageView) lViewSwitcher.getChildAt(1);
    			lViewSwitcher.setDisplayedChild(0);
    			mImageLoader.queueImageLoad(url, lImageView, lViewSwitcher);
    		} 
        //imageView.setImageDrawable(mThumbnails.get(position).image); 
        return lViewSwitcher;
	}