public class MainActivity extends Activity
{
private Button btn;
@Override
public void onCreate(Bundle savedInstanceState)
{
(savedInstanceState);
setContentView();
btn = (Button) findViewById();
(new OnClickListener()
{
@Override
public void onClick(View v)
{
//Get the LayoutInflater object, which can convert the XML file into a View object that has always been with it
LayoutInflater inflater = getLayoutInflater();
//Create a View object with hierarchical relationship based on the specified layout file
//The second parameter is the root node of the View object, that is, the ID of LinearLayout
View layout = (.toast_layout, (ViewGroup) findViewById(.toast_layout_root));
//Find ImageView control
//Note that you are looking in layout
ImageView image = (ImageView) ();
();
TextView text = (TextView) ();
("Custom Toast Demo Program");
Toast toast = new Toast(getApplicationContext());
//Set the location of Toast
(Gravity.CENTER_VERTICAL, 0, 0);
(Toast.LENGTH_LONG);
//Let Toast show it as our custom look
(layout);
();
}
});
}
}