我有一个包含天气图标的ttf文件。我想使用这些字体在listview中为每日临时创建天气图标。我已经设置好了,我在listview中也获得了图标,但是在8个listview项目中只有一个。另外,当我向上和向下滚动时,它只刷新到一个地方,而不是到处都是。我正在为我的列表视图发布getview方法,我在其中设置所有数据。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_whether_list_style, null);
holder = new ViewHolder();
holder.description = (TextView) convertView.findViewById(R.id.description);
holder.weatherIcon = (TextView) convertView.findViewById(R.id.weather_iconT);
holder.maxTemp = (TextView) convertView.findViewById(R.id.max_temp);
holder.minTemp = (TextView) convertView.findViewById(R.id.min_temp);
holder.dayName = (TextView) convertView.findViewById(R.id.day);
convertView.setTag(holder);
}
else holder = (ViewHolder)convertView.getTag();
Daily daily = dailyTest.get(position);
holder.description.setText(daily.getDescription());
holder.dayName.setText(daily.getFormattedTime());
Typeface typeface = Typeface.createFromAsset(getAssets(), "Weather&Time.ttf" );
holder.weatherIcon.setTypeface(typeface);
holder.weatherIcon.setText(daily.getWeatherIconString());
//for two digit temp format.. adding 0 for single digits.
int maxtemp = (daily.getMaxTemp()-32)*5/9;
if(maxtemp<10){
holder.maxTemp.setText("0"+ maxtemp);
} else holder.maxTemp.setText(""+ maxtemp);
int mintemp = (daily.getMinTemp()-32)*5/9;
if(mintemp<10) {
holder.minTemp.setText("0"+ mintemp);
} else holder.minTemp.setText(""+ mintemp);
return convertView;
}
答案 0 :(得分:0)
答案 1 :(得分:0)
您没有将上下文传递给createFromAsset字体,将上下文传递给createFromAsset并尝试此代码。
if(convertView==null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_whether_list_style, null);
holder = new ViewHolder();
holder.description = (TextView) convertView.findViewById(R.id.description);
holder.weatherIcon = (TextView) convertView.findViewById(R.id.weather_iconT);
holder.maxTemp = (TextView) convertView.findViewById(R.id.max_temp);
holder.minTemp = (TextView) convertView.findViewById(R.id.min_temp);
holder.dayName = (TextView) convertView.findViewById(R.id.day);
convertView.setTag(holder);
}
else holder = (ViewHolder)convertView.getTag();
Daily daily = dailyTest.get(position);
holder.description.setText(daily.getDescription());
holder.dayName.setText(daily.getFormattedTime());
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "Weather&Time.ttf" );
holder.weatherIcon.setTypeface(typeface);
holder.weatherIcon.setText(daily.getWeatherIconString());
//for two digit temp format.. adding 0 for single digits.
int maxtemp = (daily.getMaxTemp()-32)*5/9;
if(maxtemp<10){
holder.maxTemp.setText("0"+ maxtemp);
} else holder.maxTemp.setText(""+ maxtemp);
int mintemp = (daily.getMinTemp()-32)*5/9;
if(mintemp<10) {
holder.minTemp.setText("0"+ mintemp);
} else holder.minTemp.setText(""+ mintemp);
return convertView;
}