Created
September 9, 2011 09:00
-
-
Save alexvbush/1205803 to your computer and use it in GitHub Desktop.
Activity implements various OnClickListeners.
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
package com.smartcloudcompany.onclickinxml; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.Toast; | |
public class AndroidOnClickDefinitionInXMLActivity extends Activity implements OnClickListener { | |
private Button buttonWithInnerClassAsListener; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
buttonWithInnerClassAsListener = (Button) findViewById(R.id.button_with_inner_class_as_listener); | |
buttonWithInnerClassAsListener.setOnClickListener(new InnerOnClickButtonListener()); | |
} | |
/** Inner Class to respond to OnClick events. **/ | |
class InnerOnClickButtonListener implements OnClickListener { | |
public void onClick(View v) { | |
Toast.makeText(AndroidOnClickDefinitionInXMLActivity.this, "Button with Inner Class as Listener has been clicked.", 2500).show(); | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
> | |
<Button android:id="@+id/button_with_activity_as_listener" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Button with Activity As Listener" | |
android:layout_gravity="center_horizontal" | |
android:layout_marginTop="100dp" | |
/> | |
<Button android:id="@+id/button_without_listener" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Button Without listener" | |
android:layout_gravity="center_horizontal" | |
android:onClick="onButtonClick" | |
/> | |
<Button android:id="@+id/button_with_inner_class_as_listener" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Button With Inner Class As Listener" | |
android:layout_gravity="center_horizontal" | |
/> | |
<Button android:id="@+id/button_with_inline_class_as_listener" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Button With Inline Class As Listener" | |
android:layout_gravity="center_horizontal" | |
/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment