Android ImageSwitcher

2.2k Views Asked by At

I'm building an ImageSwitcher to fit in a mobile app as a banner switcher. Currently we have rotating banners using a Handler and delaying a runnable by 7 seconds(7000ms, to be exact), but we want a more fancy transition effect between two images. I'm using this as a reference, and having a horrible time doing so. I understand the concept behind it, but I want to cut the gallery part out entirely and just use the handler we we have to use the ImageSwitch transitions.

This is our code for the image switching:

private Runnable updateBannerRun = new Runnable(){
    public void run() {
        if (bannerQueue > 3){
            bannerQueue = 1;
        } else {
            bannerQueue ++;
        }
        ImageView i = (ImageView)findViewById(R.id.imageView1);
        switch (bannerQueue){
        case 1:
            i.setImageResource(R.drawable.image1);
            break;
        case 2:
            i.setImageResource(R.drawable.image2);
            break;
        case 3:
            i.setImageResource(R.drawable.image3);
            break;
        case 4:
            i.setImageResource(R.drawable.image4);
            break;
        }
        updateBanner();
    }
};

This is the code for the handler:

public void updateBanner(){
            mHandler.postDelayed(updateBannerRun, 7000);        

}

My biggest issue is when we run it, we get a nullPointException returned.

Any help would be greatly appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

You are missing the setFactory() call.

Check my blog post: Android Tip: TextSwitcher and ImageSwitcher