我正在使用此处的教程来创建自定义微调器。当我复制课程(页面中途)时CountryAdapter
,eclipse无法识别getResources()
myFlag.setBackgroundDrawable(getResources().getDrawable(item.getCountryFlag()));
有谁知道解决这个问题?基本上,我还能如何获得可绘制对象?我正在复制下面的课程
public class CountryAdapter extends ArrayAdapter<CountryInfo>
{
private Activity context;
ArrayList<CountryInfo> data = null;
public CountryAdapter(Activity context, int resource, ArrayList<CountryInfo> 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;
}
}
}