Question: I have a class that extends Activity and implements ViewFactory.

I have found some tutorials and code examples that show how to setup a [textSwitcher](http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/TextSwitcher1.html) and [imageSwitcher](http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ImageSwitcher1.html).

With both examples you have to create:

```
public View makeView() {

return x;
}  

```

Where x is either the textView or ImageView.

Here is an example of what I tried to use:

```
@Override
public View makeView() {
    ImageView iView = new ImageView(this);
    iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    iView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    iView.setBackgroundColor(0xFFFFFFFF);

    TextView t = new TextView(this);
    t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    t.setTextSize(36);

    return iView;
}

```

I can only return one of the views so I get a forced close when I try to run it with a textSwitcher called.

Any ideas? Is there a better way to do this?

Thank you,

Neil

Answer: 
As Stéphane stated before me, create an inner class implementing ViewFactory

```
public class TextSwitcherFactory implements ViewFactory
{
    @Override
    public View makeView() {
        TextView t = new TextView(Latest.this);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(36);
        return t;
    }
}

```

Then when calling the TextSwitcher from xml and setting the factory, instead of `mSwitcher.setFactory(this);`, use `mSwitcher.setFactory(new TextSwitcherFactory());` 

e.g.

```
mSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher1);
mSwitcher.setFactory(new TextSwitcherFactory());

```
You can't have the same object used as a `ViewFactory` and use it as two different factories for two different components.

I never tried it, but it here is some solution from a OO perspective :

* create two inner classes inside your activity
* both of them will implement `ViewFactory`,
* assign an instance of each inner class as the `ViewFactory` for your 2 components
* make their `makeView` method provide the needed `View` for each component

This should work,
 Stéphane