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?
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);
}
public void showToast(String text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
Another question is
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hi_button_lebel"
android:onClick="showButtonText"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bye_button_lebel"
android:onClick="showButtonText" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yo_button_lebel"
android:onClick="showButtonText" />
android:onClick="showButtonText" this is using a non-onClickListener method! How?? Please give me a detail answer. Thanks in advance. :)