滚动时滚动问题。滚动时不显示图像

时间:2016-04-05 07:30:46

标签: android scrollview android-spinner

我把一个微调器放在我的活动中,然后我放了一个textview和imageview。当我滚动时,一些图像不显示。几乎可能会显示一些未显示的图像。为enter image description here图像下方的清晰方案检查

SpinnerAdapterRecharge.java

public class SpinnerAdapterRecharge extends ArrayAdapter<listview_data> {
    private Activity context;
    listview_data data[] = null;
    int layoutResourceId;
    ImageLoader imageLoader = ImageLoader.getInstance();
    DisplayImageOptions options;
    public SpinnerAdapterRecharge(Activity context, int resource,listview_data[] data)
    {
        super(context, resource, data);
        this.context = context;
        this.data = data;
        this.layoutResourceId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        options = new DisplayImageOptions.Builder().cacheInMemory(true)
                .cacheOnDisc(true)
                .cacheInMemory(true)
                .considerExifParams(true)
                .resetViewBeforeLoading(true)
                .showImageForEmptyUri(R.drawable.imagenotavailable)
                .showImageOnFail(R.drawable.imagenotavailable)
                .showImageOnLoading(R.drawable.imagenotavailable).build();
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {   // This view starts when we click the spinner.
        return getCustomView(position, convertView, parent);
    }
    public View getCustomView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        listHolder holder = null;
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new listHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.spinnerimageIcon);
            holder.txtTitle = (TextView)row.findViewById(R.id.spinnerOperator);

            row.setTag(holder);
        }
        else
        {
            holder = (listHolder)row.getTag();
        }
        listview_data item = data[position];


        if(position == 0)
        {
            holder.imgIcon.setVisibility(View.GONE);
            holder.txtTitle.setText(context.getResources().getString(R.string.lbl_operator));
        }
        else {
            holder.txtTitle.setText(item.title);
            //holder.imgIcon.setImageResource(item.icon);
            //if (holder.imgIcon.getTag() == null ||  !holder.imgIcon.getTag().equals(item.icon)) {
                ImageAware imageAware = new ImageViewAware(holder.imgIcon, false);
                imageLoader.displayImage("drawable://"+item.icon,imageAware,options);
            //}
        }
        return row;
    }
    static class listHolder
    {
        ImageView imgIcon;
        TextView txtTitle;
    }
}

1 个答案:

答案 0 :(得分:0)

您正在使用小尺寸的Spinner,因此您无需重复使用每个项目 将您的getCustomView更改为此:

public View getCustomView(int position, View convertView, ViewGroup parent) {
        listHolder holder = new listHolder();
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        View row = inflater.inflate(layoutResourceId, parent, false);
        holder.imgIcon = (ImageView)row.findViewById(R.id.spinnerimageIcon);
        holder.txtTitle = (TextView)row.findViewById(R.id.spinnerOperator);

        listview_data item = data[position];


        if(position == 0)
        {
            holder.imgIcon.setVisibility(View.GONE);
            holder.txtTitle.setText(context.getResources().getString(R.string.lbl_operator));
        }
        else {
            holder.txtTitle.setText(item.title);
            //holder.imgIcon.setImageResource(item.icon);
            //if (holder.imgIcon.getTag() == null ||  !holder.imgIcon.getTag().equals(item.icon)) {
                ImageAware imageAware = new ImageViewAware(holder.imgIcon, false);
                imageLoader.displayImage("drawable://"+item.icon,imageAware,options);
            //}
        }
        return row;
    }