Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Toast
- FunFactsActivity.java
- private FactBook mFactBook = new FactBook();*
- private ColorWheel mColorWheel = new ColorWheel();*
- public class FunFactsActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_fun_facts);
- final TextView factLabel = (TextView) findViewById(R.id.factTextView);
- Button showFactButton = (Button) findViewById(R.id.showFactButton);
- RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.idOfRelativeLayout);
- View.OnClickListener listenerName = new View.onClickListener(){
- @Override
- public void onClick(View view) {
- String fact = mFactBook.getFact();
- factLabel.setText(fact);
- int color = mColorWheel.getColor();
- relativeLayout.setBackgroundColor(color);
- showFactbutton.setTextColor(color);
- }
- };
- showFactButton.setOnClickListener(listenerName);
- //Step 1:
- String message = "Yay! Our Activity was created!";
- Toast welcomeToast = Toast.makeText(this, message, Toast.LENGTH_LONG); //Datatype Name = Toast.makeText Method. The .makeText method
- welcomeToast.show();
- //Step 2. Refactor that^ into this:
- Toast.makeText(this, "Yay! Our Activity was created!", Toast.LENGTH_LONG).show(); // (Context, CharSequence, DurationForHowLongToastWillLast) //We use 'this' keyword refers to "this class". In this case, the FunFactsActivity. //A lot of times 'this' can substitute for Context. //CharSequence =~ String //
- }
- }
- // https://teamtreehouse.com/library/build-a-simple-android-app/testing-and-debugging/toast-notifications
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement