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”/>
…</LinearLayout>
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
btnSimple.setOnClickListener(
new OnClickListener(){
public void onClick(View v) {
Log.i(tag,”onClick Simple”);
……







