In my application I call setContentView( layout1.xml );, I want to access an element within a DIFFERENT layout file, lets call it layout2.xml.
I have tried
view1 = (View) findViewById( R.layout.layout2 );
and also added an id to the layout and tried
view1 = (View) findViewById( r.id.layout2 );
Neither of these work. They compile just fine but when I run it, as soon as i try to call something like
button1 = view1.findViewById( R.id.button1 );
I get a null pointer exception.
You need to use a layout inflater to get your second layout like so:
And then reference your button from that layout: