我正在使用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次滚动后,只能看到项目中的图像显示而所有其他文本视图都没有显示。
我在互联网上搜索过但没有找到任何解决方案。
答案 0 :(得分:0)
没有人回答,但我找到了解决方案。 经过几个小时的调试和尝试后,我发现问题在于WheelViewAdapter的自定义项目的大小。项目宽度和高度必须小于轮子小部件本身。我的更大,然后导致渲染错误是透明的(我在logcat中看不到任何错误)
我希望它有所帮助