title: Android: How to call getActivity() in OnItemClickListener()?
body: <p>I am trying to call getActivity() in the OnItemClickListener:</p>
  
  <pre><code>class ViewTest{ //called in a fragment
  setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int p, long i) {
                  ((MainActivity) getActivity()).makeResultsbarVisible();
  ...
              }
  
          });
  </code></pre>
  
  <p>}</p>
  
  <p>In the fragment, the class is instantiated as:</p>
  
  <pre><code>ViewTest editTest = new ViewTest(this);
  </code></pre>
  
  <p>But I get an error that I cannot fix:</p>
  
  <pre><code>The method getActivity() is undefined for the type new AdapterView.OnItemClickListener(){}
  </code></pre>
  
  <p>How can I call getActivity inside onItemClick()? Thanks.</p>