2013-11-22 49 views
0

我正在使用康康項目的輪轂小部件。我跟着演示。我爲輪子物品實施了自定義視圖,並且在加載大部分輪子物品之後沒有顯示出來。這裏是我的代碼:kankan.wheel.widget.WheelView。在輪子項目中的自定義視圖不會顯示

我的適配器:

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

沒有人回答,但我找到了解決方案。 經過幾個小時的調試和嘗試,我發現問題是WheelViewAdapter的自定義項目的大小。物品的寬度和高度必須小於輪子小部件本身。我的是更大的,然後導致渲染錯誤是透明的(我看不到任何錯誤logcat)

我希望它有幫助

相關問題