No actually what you describe is done by the setContentView() call. It
takes the XML layout and inflates (==creates) the associated view
instances in memory.

Then findViewById() is able to give you the view instance given its XML id.

HTH
R/

On Sat, Dec 13, 2008 at 6:04 AM, steve_macleod
<steven_macl...@hotmail.com> wrote:
>
> Hi Richard,
> OK, so it looks like the line:
>
> mLunarView = (LunarView) findViewById(R.id.lunar)
>
> creates an instance of the LunarView object, running the constructor.
> I didnt think that running the findViewById and casting to a LunarView
> would have this effect.
>
> Thanks for that
>
> On Dec 12, 5:19 pm, RichardS <richardswingw...@googlemail.com> wrote:
>> Steve,
>>
>> This is my understanding of it:
>>
>> The file res/layout/lunar_layout.xml describes the layout of the view.
>> The src/R.java file is auto generated: it equates object ids to names.
>>
>> setContentView(R.layout.lunar_layout)
>>
>> 'reads'  lunar_layout.xml file and creates and instance of the
>> LunarView class and hence the View itself.
>> If you look in the XML file it contains an Id string "@+id/lunar":
>> this is one of the ids that R.java
>> defines a name for - in this case R.id.lunar.
>>
>> mLunarView = (LunarView) findViewById(R.id.lunar)
>>
>> searches all view for the one identified by R.id.lunar ( == "@+id/
>> lunar").  This returns a reference to
>> the LunaView instance created above which we store in a member
>> variable.
>>
>> The constructor for LunarView created a private LunarThread object so
>> doing:
>>
>> mLunarThread = mLunarView.getThread()
>>
>> enables us to retrieve a reference to the thread object.
>>
>> Hope that's correct and helpful!
>>
>> richard.
>>
>> On 12 Dec, 15:49, steve_macleod <steven_macl...@hotmail.com> wrote:
>>
>>
>>
>> > Hi,
>> > I have been working through the lunarlander example application, in
>> > an
>> > attempt to understand the source code. I have run into a couple of
>> > problems, and would really appreciate if someone could space a couple
>> > of minutes to assist in may understanding.
>>
>> > The onCreate method contains the following:
>>
>> >    protected void onCreate(Bundle savedInstanceState) {
>> >         super.onCreate(savedInstanceState);
>>
>> >         // turn off the window's title bar
>> >         requestWindowFeature(Window.FEATURE_NO_TITLE);
>>
>> >         // tell system to use the layout defined in our XML file
>> >         setContentView(R.layout.lunar_layout);
>>
>> >         // get handles to the LunarView from XML, and its LunarThread
>> >         mLunarView = (LunarView) findViewById(R.id.lunar);
>> >         mLunarThread = mLunarView.getThread();
>>
>> >         // give the LunarView a handle to the TextView used for
>> > messages
>> >         mLunarView.setTextView((TextView) findViewById(R.id.text));
>>
>> >         if (savedInstanceState == null) {
>> >             // we were just launched: set up a new game
>> >             mLunarThread.setState(LunarThread.STATE_READY);
>> >             Log.w(this.getClass().getName(), "SIS is null");
>> >         } else {
>> >             // we are being restored: resume a previous game
>> >             mLunarThread.restoreState(savedInstanceState);
>> >             Log.w(this.getClass().getName(), "SIS is nonnull");
>> >         }
>> >     }
>>
>> > I can see that we are performing the following:
>> >         Turn off the title bar in the window
>> >         Set the activity content to the lunar_layour layout file
>> >         gets a reference to the 'lunar' layout
>> >         gets a reference to the thread member of the LunarView class
>> >         give the LunarView a reference to the textview for game
>> > messages
>> >         we then set the state of the lunar thread to STATE_READY,
>> > which also
>> > outputs a bunch of status messages
>>
>> > The problem is that after executution of setState, the code seems to
>> > end. I can see no sections of code that actually creates the
>> > LunarView
>> > or LunarThread objects, which are required to start the game proper.
>> > Obviously I am missing something here, I was wondering if anyone
>> > could
>> > assist! Thanks lots!- Hide quoted text -
>>
>> - Show quoted text -
> >
>

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

Reply via email to