title: Custom spinner with object ArrayAdapter can't getResources
body: <p>I am using the <a href="http://adanware.blogspot.com/2012/03/android-custom-spinner-with-custom.html" rel="nofollow">tutorial here</a> to create a custom spinner. When I copy the class <code>CountryAdapter</code> (half-way down the page), eclipse is not able to identify <code>getResources()</code> in</p>
  
  <pre><code>myFlag.setBackgroundDrawable(getResources().getDrawable(item.getCountryFlag()));
  </code></pre>
  
  <p>Does anyone know a fix to this problem? Basically, how else might I get the drawable? I am copying the class below</p>
  
  <pre><code>public class CountryAdapter extends ArrayAdapter&lt;CountryInfo&gt;
      {
          private Activity context;
          ArrayList&lt;CountryInfo&gt; data = null;
  
          public CountryAdapter(Activity context, int resource, ArrayList&lt;CountryInfo&gt; data)
          {
              super(context, resource, data);
              this.context = context;
              this.data = data;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) 
          {   // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
              return super.getView(position, convertView, parent);   
          }
  
          @Override
          public View getDropDownView(int position, View convertView, ViewGroup parent)
          {   // This view starts when we click the spinner.
              View row = convertView;
              if(row == null)
              {
                  LayoutInflater inflater = context.getLayoutInflater();
                  row = inflater.inflate(R.layout.spinner_layout, parent, false);
              }
  
              CountryInfo item = data.get(position);
  
              if(item != null)
              {   // Parse the data from each object and set it.
                  ImageView myFlag = (ImageView) row.findViewById(R.id.imageIcon);
                  TextView myCountry = (TextView) row.findViewById(R.id.countryName);
                  if(myFlag != null)
                  {
                      myFlag.setBackgroundDrawable(getResources().getDrawable(item.getCountryFlag()));
                  }
                  if(myCountry != null)
                      myCountry.setText(item.getCountryName());
  
              }
  
              return row;
          }
      }
  }
  </code></pre>