I. Toast displays an imageview
1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. widget. imageview; 5 import android. widget. toast; 6 public class ex_ctrl_3_ B extends activity {7/** called when the activity is first created. */8 @ override 9 Public void oncreate (bundle savedinstancestate) {10 super. oncreate (savedinstancestate); 11/* set the homepage Layout */12 setcontentview (R. layout. main); 13/* Create a New toast object */14 toast showimagetoast = new toast (this ); 15/* Create a New imageview object */16 imageview = new imageview (this); 17/* retrieve images from resources */18 imageview. setimageresource (R. drawable. argon); 19/* Set View -- (imageview) */20 showimagetoast on toast. setview (imageview); 21/* set the toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}
2. Toast displays a button.
1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. view. view; 5 import android. widget. button; 6 Import android. widget. toast; 7 public class ex_ctrl_3_ B extends activity {8/** called when the activity is first created. */9 @ override10 public void oncreate (bundle savedinstancestate) {11 super. oncreate (savedinstancestate); 12/* set the homepage Layout */13 setcontentview (R. layout. main); 14/* Create a New toast object */15 toast showimagetoast = new toast (this ); 16 // * Create a button object */17 button = new button (this); 18 button. settext ("OK"); 19/* Set View -- (button) */20 showimagetoast on toast. setview (button); 21/* Set toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}
3. display a textview in toast.
1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. widget. textview; 5 import android. widget. toast; 6 public class ex_ctrl_3_ B extends activity {7/** called when the activity is first created. */8 @ override 9 Public void oncreate (bundle savedinstancestate) {10 super. oncreate (savedinstancestate); 11/* set the homepage Layout */12 setcontentview (R. layout. main); 13/* Create a New toast object */14 toast showimagetoast = new toast (this); 15/* Create a textview object */16 textview text = new textview (this ); 17/* Set textview content */18 text. settext ("textview displayed in toast"); 19/* set view on toast -- (textview) */20 showimagetoast. setview (text); 21/* Set toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}