Advertisement
yo2man

Toast

Jun 22nd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. //Toast
  2. FunFactsActivity.java
  3.  
  4. private FactBook mFactBook = new FactBook();*
  5. private ColorWheel mColorWheel = new ColorWheel();*
  6.  
  7. public class FunFactsActivity extends Activity {
  8. @Override
  9.     public void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_fun_facts);
  12.  
  13.         final TextView factLabel = (TextView) findViewById(R.id.factTextView);
  14.         Button showFactButton = (Button) findViewById(R.id.showFactButton);
  15.        
  16.         RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.idOfRelativeLayout);
  17.  
  18.         View.OnClickListener listenerName = new View.onClickListener(){
  19.                
  20.                 @Override
  21.                 public void onClick(View view) {
  22.  
  23.                 String fact = mFactBook.getFact();
  24.                 factLabel.setText(fact);
  25.  
  26.                 int color = mColorWheel.getColor();
  27.                 relativeLayout.setBackgroundColor(color);
  28.  
  29.                 showFactbutton.setTextColor(color);
  30.                                }
  31.         };
  32.                
  33.         showFactButton.setOnClickListener(listenerName);
  34.  
  35.     //Step 1:
  36.     String message = "Yay! Our Activity was created!";
  37.     Toast welcomeToast = Toast.makeText(this, message, Toast.LENGTH_LONG); //Datatype Name = Toast.makeText Method. The .makeText method
  38.     welcomeToast.show();
  39.  
  40.     //Step 2. Refactor that^ into this:
  41.     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 //
  42.     }
  43. }
  44.  
  45.  
  46. // https://teamtreehouse.com/library/build-a-simple-android-app/testing-and-debugging/toast-notifications
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement