title: Get view for button click on the Fragment of the ViewPager
body: <p>I have successfully set up the a <code>FragmentActivity</code> with <code>FragementPagerAdapter</code> associated with <code>ViewPager</code> to implement two tabbed application .</p>
  
  <p>One of the Tabs namely "Wave" has a text view and a button . All I want is call  <code>textview.setText</code> method via the <code>onClick</code> method of button described by its xml attribute .</p>
  
  <p>I do not know where should I initialize my <code>TextView</code> or <code>Button</code> , how can I get the <code>context</code> of Wave tab and where should I write <code>onclick method</code>-</p>
  
  <pre><code>public class InformationShow extends FragmentActivity {
  
  XMLdata dataObject;
  
  ViewPager viewPager;
      PagerAdapter adpt;
  
  
      Fragment temp;  
      TextView tv;
      Button bt;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.fragment_main);
          viewPager=(ViewPager)findViewById(R.id.pager);
              adpt  =  new  PagerAdapter(getSupportFragmentManager());
          viewPager.setAdapter(adpt);
        // temp=adpt.fg.findFragmentById((int)adpt.getItemId(1));
  
     tv=(TextView)findViewById(R.id.graphWaveTextView);
     bt = (Button)findViewById(R.id.button1);
  
       }
  
  
   public void changeText(View v){
  
    tv.setText("It worked ");
   }
  </code></pre>
  
  <p><strong>Adapter Class</strong></p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  int count = 2;
  CharSequence namme[] = {"Temperature","Wave"}; 
  XMLdata data;
  FragmentManager fg;
  public  PagerAdapter(FragmentManager fragmentManager ){
      super(fragmentManager);
      this.fg = fragmentManager;
  }
  Context context;
  
  @Override
  public Fragment getItem(int arg0) {
  
      switch (arg0){
  
      case 0:{    
  
          TemperatureGraphFrag temp = new TemperatureGraphFrag();
  
          return temp;
  
      } 
  
  
      case 1:{WaveHeightGraphFrag wave = new WaveHeightGraphFrag();
  
      return wave;
      } 
  
  
  
  
      }
  
      return null;
  }
  
  
  
  
  
  
  @Override
  public int getCount() {
      return 2;
  }
  
  
  
  @Override
  public CharSequence getPageTitle(int position) {
  return namme[position];
  }
  
  
  
  
      }
  </code></pre>
  
  <p><strong>Fragments Class</strong></p>
  
  <pre><code>public class TemperatureGraphFrag extends Fragment {
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
      View    view = inflater.inflate(R.layout.graph_t, container, false);
          return view;
      }
  
  
  
  }
  
  
  public class WaveHeightGraphFrag extends Fragment  {
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
      View    view = inflater.inflate(R.layout.graph_sig_wave_height, container, false);
  
  
      return view;
  
  
      }
  
  
  
  
  }
  </code></pre>
  
  <p><strong>fragment_main XML</strong> implemented by <code>FragmentActicity</code></p>
  
  <pre><code>&lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;android.support.v4.view.PagerTabStrip
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="top"
          android:paddingBottom="10dp"
          android:paddingTop="10dp"
          android:textColor="#65C2C9"
          android:scrollbarSize="5dp"/&gt;
  
  
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p><strong>Tab 2 Fragment XML graph_sig_wave_height</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
  
  
       &gt;
  
      &lt;TextView
          android:id="@+id/graphWaveTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Small Text"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:layout_gravity="center"
  
  
           /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button"
  
          android:layout_gravity="center" 
          android:onClick="changeText"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Tab 1 fragment layout XML    graph_t</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:id="@+id/linearTemp"
       &gt;
  
      &lt;TextView
          android:id="@+id/graphTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Medium Text"
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:layout_gravity="center"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>