How to write button click even in ViewPager
<p>Here my activity_main.xml present in /res/layout</p>

<pre><code>&lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" &gt;

    &lt;!--
    This title strip will display the currently visible page title, as well as the page
    titles for adjacent pages.


    --&gt;

    &lt;android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" /&gt;

&lt;/android.support.v4.view.ViewPager&gt;
</code></pre>

<p>Here is my MainActivity.java file</p>

<pre><code>import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

import android.view.ViewGroup;

public class MainActivity extends FragmentActivity {

    SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the app.
        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a DummySectionFragment (defined as a static inner class
            // below) with the page number as its lone argument.
            Fragment fragment = new DummySectionFragment();
            Bundle args = new Bundle();
            args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
            case 0:
                return "POS 0"; // getString(R.string.title_section1).toUpperCase();
            case 1:
                return "POS 1";// getString(R.string.title_section2).toUpperCase();
            case 2:
                return "POS 2";// getString(R.string.title_section3).toUpperCase();
            }
            return null;
        }
    }

    /**
     * A dummy fragment representing a section of the app, but that simply
     * displays dummy text.
     */
    public static class DummySectionFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        public static final String ARG_SECTION_NUMBER = "section_number";

        public DummySectionFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View view;
            String i = Integer.toString(getArguments().getInt(
                    ARG_SECTION_NUMBER));

            if (i.toString() == Integer.toString(1)) {
                view = inflater.inflate(R.layout.section2, container, false);
            } else {
                view = inflater.inflate(R.layout.section1, container, false);


                // Button button = (Button) view.findViewById(R.id.button1);
                // button.setOnClickListener(new OnClickListener() {
                // if i uncomment this code, button click works but i want it to handle in section1.java file
                // @Override
                // public void onClick(View v) {
                // Activity activity = getActivity();
                //
                // if (activity != null) {
                // Toast.makeText(activity, "sdfsdfsdfds",
                // Toast.LENGTH_LONG).show();
                // }
                // }
                //
                // });

            }

            return view;

        }
    }

}
</code></pre>

<p>I have an activity named "Section1" which is displayed when i swipe to right side. It has a button on it. 
How do i handle the button click event in section1.java file ?</p>

<p>here is my section.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Section1" &gt;

    &lt;Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="sendMessage"
        android:text="Button" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>Here is the Section1.Java file. Here button click even it not fired.</p>

<pre><code>import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class Section1 extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.section1);

    }

    public void sendMessage(View view) {
        Toast t = Toast.makeText(getApplicationContext(), "sdfsdfsdf",
                Toast.LENGTH_LONG);
        t.show();
    }

}
</code></pre>
