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 trialJarvis Chandler
7,619 PointsApp seems to rest the color back to green and give me the Toast message "Yay! Our Activity was created!"
nfacts;
import android.content.Intent; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast;
import java.util.Random;
public class FunFactsActivity extends AppCompatActivity {
public static final String TAG = FunFactsActivity.class.getSimpleName();
private static final String KEY_FACT = "KEY_FACT";
private static final String KEY_COLOR = "KEY_COLOR";
private FactBook mFactBook = new FactBook();
private ColorWheel mColorWheel = new ColorWheel();
private String mFact = mFactBook.mFacts[0];
private int mColor = Color.parseColor(mColorWheel.mColors[8]);
private RelativeLayout mRelativeLayout;
private Button mShowFactButton;
private TextView mFactLabel;
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_FACT, mFact);
outState.putInt(KEY_COLOR, mColor);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mFact = savedInstanceState.getString(KEY_FACT);
mRelativeLayout.setBackgroundColor(mColor);
mFactLabel.setText(mFact);
mShowFactButton.setTextColor(mColor);
mColor = savedInstanceState.getInt(KEY_COLOR);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
mFactLabel = (TextView) findViewById(R.id.factTextView);
mShowFactButton = (Button) findViewById(R.id.showFactButton);
mRelativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
mFact = mFactBook.getFacts();
mFactLabel.setText(mFact);
mColor = mColorWheel.getColor();
mRelativeLayout.setBackgroundColor(mColor);
mShowFactButton.setTextColor(mColor);
}
};
mShowFactButton.setOnClickListener(listener);
Toast.makeText(this, "Yay! Our Activity was created!", Toast.LENGTH_LONG).show();
Log.d(TAG, "We're logging from the onCreate() method!" );
}
}
Jarvis Chandler
7,619 PointsNot sure? I changed the get color and reentered it and it worked.? Not Really sure how what to say but thanks for the response back.
1 Answer
Placinta Alexandru
3,011 PointsYou get the toast message because of the line before the last line, the "Toast class method" one. That give u the message when you open the app. Just coment that line or remove it from ypur code
Royce Foo Wai Kit
2,551 PointsRoyce Foo Wai Kit
2,551 PointsJust curious
mRelativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout<<<);
is it supposed to be small letter for relativeLayout or RelativeLayout ?