Hello,
I'm building a simple game.
While the user is playing the game, I want the background to be changed in a loop.
I have created I new thread which need should do the background replacing job.
The layout of the game is build from an xml file which looks like this:
as you can see the is an liniar layout which id is - "game_main_layout"
In my thread, i'm trying to tell it to get this layout, like this:
but some how i get null.
Some body can explain to me why? I do I do this properly?
Thanks in advance.
I'm building a simple game.
While the user is playing the game, I want the background to be changed in a loop.
I have created I new thread which need should do the background replacing job.
The layout of the game is build from an xml file which looks like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding ="20dp"
android:id="@+id/game_main_layout"
android:background="@drawable/game_3"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:id="@+id/tableLayout1"
android:layout_gravity="center"
android:background="@color/game_background"
>
<TableRow>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" />
</TableRow>
<TableRow>
<Button android:text="Button" android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
</TableRow>
<TableRow>
<Button android:text="Button" android:id="@+id/button9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button11" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button12" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
</TableRow>
<TableRow>
<Button android:text="Button" android:id="@+id/button13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button14" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button15" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
<Button android:text="Button" android:id="@+id/button16" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" />
</TableRow>
</TableLayout>
</LinearLayout>
as you can see the is an liniar layout which id is - "game_main_layout"
In my thread, i'm trying to tell it to get this layout, like this:
Code:
LinearLayout someView = (LinearLayout)findViewById(R.id.game_main_layout);
but some how i get null.
Some body can explain to me why? I do I do this properly?
Thanks in advance.