Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
partha chakraborty
10,562 PointsMy version of the funfacts app not running on my Sony LT26i
I have trying to make a different version of the Funfacts app but instead of showing facts and changing background color, my app changes the background image on clicking the 'Change Background' button.
The app runs on the emulator but not on my mobile.
Here is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:background="@drawable/my_img1" android:id="@+id/bgImage" > <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change Background"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And here is MainActivity.java:
final int[] img = {R.drawable.my_img2,R.drawable.my_img3};
final RelativeLayout background = (RelativeLayout) findViewById(R.id.bgImage);
Button button = (Button) findViewById(R.id.button);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
Random randomGen = new Random();
int randomNumber = randomGen.nextInt(img.length);
int image = img[randomNumber];
background.setBackgroundResource(image);