Home > Google Android > Handle onClick event using XML

Handle onClick event using XML

This is simple example how to handle onClickButtonEvent().  Situation at the beginning is following.  You have defined  some_activity.xml stored inside project res/layout folder .  This code snipped is defined inside XML file:

<LinearLayout ….
<Button android:id=”@+id/home_btn_even”    style=”@style/EventButton”   android:onClick=”onClickButtonEvent”    android:text=”@string/btn_event”       android:drawableTop=”@drawable/home_btn_event”/>

Let’s aim at  android:onClick=”onClickButtonEvent”  … The button is displayed inside the main Activity where is defined the method

public class MainActivity extends Activity implements AsyncQueryListener, Receiver
/** Handle “on ClickEvent” action. */
public void onClickButtonEvent(View v) {
startActivity(new Intent(Intent.ACTION_VIEW, Object.CONTENT_URI));

it’s better and more effective than following code snipped

new OnClickListener(){
public void onClick(View v) {
Log.i(tag,”onClick Simple”);

Categories: Google Android
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: