Instantly share code, notes, and snippets.
- Toronto, Canada
choiboi
/ android_button_instantiate_listener.java
Last active
August 29, 2015 14:03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Button listener implemented by not implmenting this class with | |
// OnClickListener. When button is pressed, it will invoke the onClick method | |
// inside the OnClickListener object created when the listener has been set. | |
Button implementListenerButton = (Button) findViewById(R.id.button_object_onclicklistener); | |
implementListenerButton.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View arg0) { | |
Toast.makeText(ButtonMainActivity.this, "Button listener created while setting the button listener pressed!", Toast.LENGTH_LONG).show(); | |
} | |
}); |
choiboi
/ android_button_xml_listener_java.java
Created
July 9, 2014 20:26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method will invoke with the button that has the xml attribute onClick set with this method name. | |
public void onButtonPressed(View v) { | |
Toast.makeText(this, "Button listener implemented xml onClick attribute!", Toast.LENGTH_LONG).show(); | |
} |
choiboi
/ android_button_xml_listener_xml.xml
Created
July 9, 2014 20:28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Must have onClick attribute with the method name as the value. --> | |
<Button | |
android:id="@+id/button_xml_attribute" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/button_xml_attribute_text" | |
android:onClick="onButtonPressed" /> |
choiboi
/ android_button_implement_listener.java
Created
July 9, 2014 20:33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overriden onClick method. This method will invoke for buttons that has been set with the on click listener | |
// with this class. | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(this, "Button listener implemented through this class pressed!", Toast.LENGTH_LONG).show(); | |
} |
OlderNewer