我正在使用来自 kankan 项目的轮子小部件。我跟着演示。我为轮子项目实现了一个自定义视图,加载后大部分轮子项目都没有显示。这是我的代码:
我的适配器:
public class MyAdapter implements WheelViewAdapter {
// Countries names
static class ViewHolder {
TextView tvUserName;
TextView tvcountry;
TextView tvAge;
TextView tvPlayTime;
ImageView imProfilePhoto;
}
private User[] fans;
User fan;
Context con;
// Countries flags
/**
* Constructor
*/
public MyAdapter(Context context, User[] fans) {
super();
this.fans = fans;
con = context;
//setItemTextResource(R.id.textViewCountryV);
}
@Override
public View getItem(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//super.getItem(poition, convertView, parent);
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) con
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fan_roulette_item, parent, false);
holder = new ViewHolder();
holder.imProfilePhoto = (ImageView) convertView.findViewById(R.id.ivProfilePhoto);
fan = this.fans[position];
holder.tvcountry = (TextView) convertView.findViewById(R.id.textViewCountryV);
holder.tvAge = (TextView) convertView.findViewById(R.id.textViewAgeV);
holder.tvPlayTime = (TextView) convertView.findViewById(R.id.textViewPlayTimeV);
holder.tvUserName = (TextView) convertView.findViewById(R.id.textViewUserNameV);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MainActivity.myImageLoader.DisplayImage(fans[position].imageURL,
holder.imProfilePhoto, true);
holder.tvUserName.setText(fan.username);
holder.tvcountry.setText(fan.country);
holder.tvAge.setText("" + fan.age);
holder.tvPlayTime.setText("" + fan.playTime);
return convertView;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) con
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fan_roulette_item, parent, false);
holder = new ViewHolder();
holder.imProfilePhoto = (ImageView) convertView.findViewById(R.id.ivProfilePhoto);
fan = this.fans[position];
holder.tvcountry = (TextView) convertView.findViewById(R.id.textViewCountryV);
holder.tvAge = (TextView) convertView.findViewById(R.id.textViewAgeV);
holder.tvPlayTime = (TextView) convertView.findViewById(R.id.textViewPlayTimeV);
holder.tvUserName = (TextView) convertView.findViewById(R.id.textViewUserNameV);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MainActivity.myImageLoader.DisplayImage(fans[position].imageURL,
holder.imProfilePhoto, true);
holder.tvUserName.setText(fan.username);
holder.tvcountry.setText(fan.country);
holder.tvAge.setText("" + fan.age);
holder.tvPlayTime.setText("" + fan.playTime);
return convertView;
}
@Override
public int getItemsCount() {
return fans.length;
}
public User getCurrentItem(int currentWheelItem) {
return this.fans[currentWheelItem];
}
@Override
public View getEmptyItem(View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
}
症状是:刚开始加载轮子时,有时我可以看到我的自定义项目,有时我看不到。滚动 10 次中的 9 次后,只能看到项目中的图像显示,而所有其他文本视图均未显示。
我在互联网上进行了搜索,但没有找到任何解决方案。