2010-03-02

How to set a listener to a button in Android.

In XML file

<Button android:id="@+id/PhotosBtn" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:gravity="center"
    android:text="photos" />

In Java file

View photosButton = findViewById(R.id.PhotosBtn);
photosButton.setOnClickListener(this);

Then implement the onClick(View v) method as you desire.

No comments: