title: android custom toasts
body: <p>I was able to make custom toast using this code</p>
  
  <pre><code>    LayoutInflater inflater = getLayoutInflater();
  
      View layout = inflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast));
  
      TextView text = (TextView) layout.findViewById(R.id.toast_tv);
      text.setText("Hello! This is a custom toast!");
  
      Toast toast = new Toast(getApplicationContext());       
      toast.setDuration(Toast.LENGTH_LONG);
      toast.setView(layout);
      toast.show();
  </code></pre>
  
  <p>However, since I do not understand the purpose of <code>LayoutInflater</code>, I modified the code to this...</p>
  
  <pre><code>Toast toast = new Toast(getApplicationContext());
      toast.setView(findViewById(R.id.custom_toast));
      toast.setDuration(Toast.LENGTH_SHORT);
      toast.show();
  </code></pre>
  
  <p>And I get RuntimeException saying "setView must have been called".. </p>
  
  <ul>
  <li><p>Why can't I just assign the view to toast without using <code>LayoutInflater</code>? </p></li>
  <li><p>What is the purpose of <code>LayoutInflater</code> in general so that I can apply this experience to other custom views?</p></li>
  </ul>
  
  <p><strong>Edit:</strong>
  I am using these codes in <code>onListItemClick()</code> interface method.. after the content is set..</p>