我正在考虑编写一个自定义适配器来填充列表视图,每行3个textview.我已经找到了相当多的示例代码来执行此操作,但看起来最好的代码是:http://www.anddev.org/custom_widget_adapters-t1796.html
经过一些小的调整来修复最新的Android SDK的一些编译器问题后,我让它运行,只是为了得到异常:
ERROR/AndroidRuntime(281):java.lang.UnsupportedOperationException:AdapterView不支持addView(View,LayoutParams)
所以我做了很多研究,发现了很多可能的原因和解决方法.这些都没有改变.我的适配器代码目前是:
public class WeatherAdapter extends BaseAdapter {
private Context context;
private List<Weather> weatherList;
public WeatherAdapter(Context context, int rowResID,
List<Weather> weatherList ) {
this.context = context;
this.weatherList = weatherList;
}
public int getCount() {
return weatherList.size();
}
public Object getItem(int position) {
return weatherList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
Weather weather = weatherList.get(position);
//LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = LayoutInflater.from(context); …Run Code Online (Sandbox Code Playgroud)