Like I said in your other thread, you probably don't want to be doing this.
If I am to assume from your code-snippet that you have some kind of PacMan
game, where the game is implemented in a SurfaceView and the PacMan is an
ImageView...  seriously, you don't want to do this.

The purpose of SurfaceView is to give you a dedicated drawing surface, which
you can render to directly, independently of the  normal update mechanism of
the view hierarchy.  Using an ImageView to render things completely defeats
that purpose.  If you are writing a game, you should be drawing your
graphics into the SurfaceView yourself and not using the view hierarchy of
managing the element there.

On Sun, May 17, 2009 at 5:16 PM, steve_macleod
<[email protected]>wrote:

>
> So if I had:
>
> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>     android:layout_width="fill_parent"
>    android:layout_height="fill_parent">
>
> <android.pacman.com.PacManMainView
>      android:id="@+id/pacman_main_view"
>      android:layout_width="fill_parent"
>      android:layout_height="fill_parent">
> </android.pacman.com.PacManMainView>
>
> <ImageView android:id="@+id/pacAnim"
>     android:src="@drawable/pac02"
>     android:layout_width="20px"
>     android:layout_height="20px"/>
> </FrameLayout>
>
> How would I go about getting a reference to the ImageView from
> PamManMainView?
>
> Thanks again
>
>
>
> On 18 May, 00:56, Marco Nelissen <[email protected]> wrote:
> > If this is indeed the case, then the ImageView isn't actually there,
> > so you can't get a reference to it.
> >
> > On Sun, May 17, 2009 at 4:45 PM, steve_macleod
> >
> >
> >
> > <[email protected]> wrote:
> >
> > > Thanks for the reply.
> > > Ill look into this. What is the best way to get a reference to the
> > > ImageView from the custom view code, if this is the case?
> >
> > > On 18 May, 00:19, Marco Nelissen <[email protected]> wrote:
> > >> I'm not 100% sure, but I don't think a SurfaceView can have child
> > >> views (since it's not a ViewGroup).
> >
> > >> On Sun, May 17, 2009 at 2:53 PM, steve_macleod
> >
> > >> <[email protected]> wrote:
> >
> > >> > Hi,
> > >> > I have the following xml layout:
> >
> > >> > <android.pacman.com.PacManMainView
> > >> >      android:id="@+id/pacman_main_view"
> > >> >      android:layout_width="fill_parent"
> > >> >      android:layout_height="fill_parent">
> >
> > >> >       <ImageView android:id="@+id/pacAnim"
> > >> >                        android:src="@drawable/pac02"
> > >> >                        android:layout_width="20px"
> > >> >                        android:layout_height="20px"/>
> >
> > >> > </android.pacman.com.PacManMainView>
> >
> > >> > PacManMainView extends SurfaceView. I can draw to this, it works OK.
> > >> > However, when I attempt to get a reference to the ImageView from
> > >> > PacManMainView like this:
> >
> > >> > @Override
> > >> > public void surfaceCreated(SurfaceHolder holder) {
> > >> >   /* test reference to imageview
> > >> >   ImageView pacImageV = (ImageView) findViewById(R.id.pacAnim);
> > >> > }
> >
> > >> > I get a null each time. Is there something real simple Im missing?
> >
> > >> > Thanks- Hide quoted text -
> >
> > >> - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to