I ended up changing extending a View to a FrameLayout.  This way I
can use it as the root in inflate because it is a ViewGroup.  I think
the problem was that having a null parent in an inflate  doesnt
actually render the views.  I may be wrong about this but it worked
for me.

Caching the subviews in onFinishInflate() is a good idea, so i did
that too.

Thanks.

On Jan 19, 5:25 pm, Jason Proctor <jason.android.li...@gmail.com>
wrote:
> override onFinishInflate() and cache your subviews there. the view
> constructor is too early for findViewById().
>
>
>
> >I have an activity defined as:
>
> >public class FlipperDemo extends Activity
> >{
> >   �...@override
> >    public void onCreate( Bundle savedInstanceState )
> >    {
> >            super.onCreate( savedInstanceState );
> >            setContentView( R.layout.main );
> >    }
> >}
>
> >With this in main.xml
>
> ><?xml version="1.0" encoding="utf-8"?>
> >   <com.test.MyFlipper
> >     xmlns:android="http://schemas.android.com/apk/res/android";
> >     android:layout_width="wrap_content"
> >     android:layout_height="wrap_content"  />
>
> >MyFlipper.java contains
>
> >class MyFlipper extends View
> >{
> >         public MyView( Context context, AttributeSet attrs )
> >         {
> >            super( context, attrs );
> >            ViewFlipper flipper1 = (ViewFlipper) LayoutInflater.from
> >( context ).inflate( R.layout.myflipper, null );
> >                 ViewFlipper flipper2 = (ViewFlipper) findViewById
> >( R.id.flipper );
> >         }
> >}
>
> >And myflipper.xml contains
>
> ><?xml version="1.0" encoding="utf-8"?>
> >     <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/
> >android"
> >         android:id="@+id/flipper"
> >         android:layout_width="fill_parent"
> >         android:layout_height="fill_parent" >
>
> >         <Button
> >             android:id="@+id/button1"
> >             android:layout_width="fill_parent"
> >             android:layout_height="fill_parent" />
>
> >         <Button
> >             android:id="@+id/button2"
> >             android:layout_width="fill_parent"
> >             android:layout_height="fill_parent" />
> >     </ViewFlipper>
>
> >The problem is that in the MyView() constructor flipper1 gets set, but
> >flipper2 is null!  Why cant i get flipper by Id here?
>
> >--
> >You received this message because you are subscribed to the Google
> >Groups "Android Developers" group.
> >To post to this group, send email to android-developers@googlegroups.com
> >To unsubscribe from this group, send email to
> >android-developers+unsubscr...@googlegroups.com
> >For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> jason.vp.engineering.particle
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to