kankan.wheel.widget.WheelView. Custom views in the wheel item arent being shown

StackOverflow https://stackoverflow.com/questions/20146113

  •  03-08-2022
  •  | 
  •  

سؤال

I am using the wheel widget from the kankan project. I followed the demo. I implemented a custom view for the wheel items and after loading most of the wheel items are not being shown. Here is my code:

My Adapter:

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
    }
}

The symptoms are: at the beginning when the wheel is loaded, sometimes I can see my custom items and sometimes not. After scrolling in 9 out of 10 times a can see only the image in the item is shown and all the other textviews are not.

I have searched over the internet but haven't found any solution.

هل كانت مفيدة؟

المحلول

Nobody answered but i found the solution. After hours of debugging and tries, i figured out that the problem was with the size of the custom items of the WheelViewAdapter. the item width and height has to be smaller then the wheel widget itself. mine was bigger, then caused rendering errors which were transparent (i couldn't see any error in logcat)

i hope it helps

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top