Button can be added to the screen in
two ways. One is through XML and the other is through java.
Click event should be handled only in
java. This related code should be written in onCreate() method.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Clear" /> </LinearLayout>
public void onCreate(Bundle b){ Button clearbutton=(Button)findViewById(R.id.button); OnClickListener clearButtonlistener = new OnClickListener(){ public void onClick(View viewParam) { //Add OnclickEvent Handling logic at this part. } }; }