Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this code make the toast? There is no listener
    primarykey
    data
    text
    <p>I've found a piece of code for making toast message. As a new android developer, i know that, we have a listener to make a button working. But here there is no listener. So why this code is working?</p> <pre><code> public class MainActivity extends Activity { private String mButtonMessageTemplate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonMessageTemplate=getString(R.string.button_messege_template); } public void showButtonText(View clickedButton){ Button button=(Button) clickedButton; CharSequence text=button.getText(); String message=String.format(mButtonMessageTemplate, text); showToast(message); </code></pre> <p>}</p> <pre><code>public void showToast(String text) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); </code></pre> <p>}</p> <p>Another question is</p> <pre><code> &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hi_button_lebel" android:onClick="showButtonText"/&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/bye_button_lebel" android:onClick="showButtonText" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/yo_button_lebel" android:onClick="showButtonText" /&gt; </code></pre> <p>android:onClick="showButtonText" this is using a non-onClickListener method! How?? Please give me a detail answer. Thanks in advance. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload