title: ListView inside of ViewPager
body: <p>So I have a ListView inside of a ViewPager.</p>
  
  <p>I have the <code>ListView</code> in one layout <code>(add_site.xml)</code> and an <code>EditText</code> field that would populate the <code>ListView</code> <code>onClick</code> on another layout <code>(main.xml)</code></p>
  
  <p>I'm getting an NPE error because I tried to put the ArrayAdapter globlaly thinking that was the right approach to be able talk to both of those layouts in the <code>ViewPager</code>.</p>
  
  <p>Clearly my android dev skills aren't that great. I'm pretty new at this.</p>
  
  <p>So any help is appreciated! </p>
  
  <p>Here's my code.</p>
  
  <p>This is where the PagerAdapter begins</p>
  
  <pre><code> private class MyPagerAdapter extends PagerAdapter {
  
      final ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);
  
      public int getCount() {
          return 3;
      }
  
      public Object instantiateItem(View collection, int position) {
  
          LayoutInflater inflater = (LayoutInflater) collection.getContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          ListView lv = (ListView)findViewById(android.R.id.list);
  
          final ArrayList&lt;String&gt; siteList = new ArrayList&lt;String&gt;();
          final ArrayAdapter&lt;String&gt; aa;
          aa = new ArrayAdapter&lt;String&gt;(getBaseContext(), R.layout.list_row, siteList);
          lv.setAdapter(aa);
  
          int resId = 0;
          View view = null;
          switch (position) {
              case 0:
                  resId = R.layout.field01;
                  view = inflater.inflate(resId, null);
                  ((ViewPager) collection).addView(view, 0);
  
                  return view;
  
              case 1: //ListView lives in here.
                  resId = R.layout.add_site; 
                  view = inflater.inflate(resId, null);
                  Button addSiteButton = (Button)view.findViewById(R.id.addSiteButton);
                  ((ViewPager) collection).addView(view, 0);
                  addSiteButton.setOnClickListener(new View.OnClickListener() {
  
                      @Override
                      public void onClick(View v) {
                        mPager.setCurrentItem(2, true);
                      }
  
                  });
  
                  //I originally had the ArrayAdapter code here, but thought it needed to be global so I moved it up.
  
                  return view;
  
              case 2:
                  resId = R.layout.main;
                  view = inflater.inflate(resId, null);
                  Button signInButton = (Button)view.findViewById(R.id.sign_in_button);
  
                  //This is where the EditText lives
                  final EditText editText = (EditText)view.findViewById(R.id.textViewId);
                  ((ViewPager) collection).addView(view, 0);
                  signInButton.setOnClickListener(new View.OnClickListener() {
  
                      @Override
                      public void onClick(View v) {
                          //This is where the button click happens
                          siteList.add(0, editText.getText().toString());
                          aa.notifyDataSetChanged();
                          editText.setText("");
                          mPager.setCurrentItem(1, true);
                      }
  
                  });
                  return view;
          }
  
          return view;
      }
  </code></pre>
  
  <p>Thanks in advanced!</p>