列表视图改变在滚动的ImageView的位置 [英] List View changes position of ImageView On scroll

查看:123
本文介绍了列表视图改变在滚动的ImageView的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用列表视图自定义阵列适配器从sqlite的适配器的数据集。但是,当列表中的项目达到了10(或名单滚动能)图像视图自动改变位置,如果我继续滚动。这里是我的自定义适配器的code.Thanks

 公共类CustomeAdapter扩展ArrayAdapter<串GT; {
 公共上下文的背景下; 公众的ArrayList<串GT; titleArrayList,descArrayList,timeArrayList,imgArrayList,IdArrayList;
    列表数据;
    INT layoutResID;
    私人位图MYBITMAP;    公共CustomeAdapter(上下文的背景下,INT layoutResourceId,ArrayList的<弦乐> titleArrayList,ArrayList的<弦乐> descArrayList,ArrayList的<弦乐> timeArrayList,ArrayList的<弦乐> imgArrayList,ArrayList的<弦乐> IdArrayList){
        超(背景下,layoutResourceId,titleArrayList);
        this.context =背景;
        this.titleArrayList = titleArrayList;
        this.descArrayList = descArrayList;
        this.timeArrayList = timeArrayList;
        this.imgArrayList = imgArrayList;
        this.IdArrayList = IdArrayList;
        this.data =数据;
        this.layoutResID = layoutResourceId;    }    @覆盖
    公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
        查看rowView = convertView;
        最后StockQuoteView sqView;        如果(rowView == NULL){
            LayoutInflater充气=((活动)上下文).getLayoutInflater();
            rowView = inflater.inflate(layoutResID,父母,假);
            sqView =新StockQuoteView();
            sqView.tag =(TextView中)rowView.findViewById(R.id.tv_fullnote);            sqView.desc =(TextView中)rowView.findViewById(R.id.tv_title);
            sqView.time =(TextView中)rowView.findViewById(R.id.tv_time);
            sqView.id =(TextView中)rowView.findViewById(R.id.id);
            sqView.img =(ImageView的)rowView.findViewById(R.id.imageView3);            sqView.button1 =(ImageView的)rowView.findViewById(R.id.swipe_button1);
            sqView.button2 =(ImageView的)rowView.findViewById(R.id.swipe_button2);
            sqView.button3 =(ImageView的)rowView.findViewById(R.id.swipe_button3);
            sqView.button4 =(ImageView的)rowView.findViewById(R.id.swipe_button4);
            rowView.setTag(sqView);
        }其他{
            sqView =(StockQuoteView)rowView.getTag();
        }        尝试{
            sqView.tag.setText(titleArrayList.get(位置));
            sqView.desc.setText(descArrayList.get(位置));
            sqView.time.setText(timeArrayList.get(位置));
            sqView.id.setText(IdArrayList.get(位置));
            sqView.id.setTag(IdArrayList.get(位置)的ToString());
            如果(imgArrayList.get(位置)。载(空)){
                sqView.img.setImageBitmap(NULL);
                sqView.img.setTag(空);
            }其他{
                MYBITMAP = BitmapFactory.de codeFILE(imgArrayList.get(位置));
                //sqView.img.setImageBitmap((position&功放; 1)== 1 MYBITMAP:MYBITMAP);?
                字符串标记=标记;
                字符串ID =将String.valueOf(位置);                sqView.img.setTag(imgArrayList.get(位置)的ToString());
                INT宽度= myBitmap.getWidth();
                INT高度= myBitmap.getHeight();
                INT newWidth =(身高>宽度)?宽:高;
                INT newHeight =(身高>宽度)?高度 - (高 - 宽):高度;
                INT作物=(宽 - 高)/ 2;
                作物=(作物℃下)? 0:作物;
                位图cropImg = Bitmap.createBitmap(MYBITMAP,裁剪,0,newWidth,newHeight);
                sqView.img.setImageBitmap(cropImg);
            }
        }赶上(例外五){
            System.out.print(e.toString());
        }
        返回rowView;
    }    保护静态类StockQuoteView {
        保护的TextView标签;
        保护TextView的说明;
        保护TextView的时间;
        保护ImageView的IMG;
        保护ImageView的按钮1;
        保护ImageView的按钮2;
        保护ImageView的按钮3;
        受保护的ImageView将Button4;
        公共TextView的ID;
    }
}
`


解决方案

把这行 sqView.img.setVisibility(View.INVISIBLE) sqView.img.setTag(空); 做优做强可见背面的ImageView在else说明书如其他{sqView.img.setVisibility(View.VISIBLE)
                MYBITMAP = BitmapFactory.de codeFILE(imgArrayList.get(位置));
                //sqView.img.setImageBitmap((position&功放; 1)== 1 MYBITMAP:MYBITMAP);?
                字符串标记=标记;
                字符串ID =将String.valueOf(位置); ............}

这只是欺骗。

I am using List View with custom array adapter the adapter sets data from Sqlite. But when the list items reach over 10 (or list becomes scroll able) the Image View changes position automatically if i scrolls continue. here is my custom adapter's code.Thanks

public class CustomeAdapter extends ArrayAdapter<String>{
 public Context context;

 public ArrayList<String> titleArrayList, descArrayList, timeArrayList, imgArrayList, IdArrayList;
    List data;
    int layoutResID;
    private Bitmap myBitmap;

    public CustomeAdapter(Context context, int layoutResourceId, ArrayList<String> titleArrayList, ArrayList<String> descArrayList, ArrayList<String> timeArrayList, ArrayList<String> imgArrayList, ArrayList<String> IdArrayList) {
        super(context, layoutResourceId, titleArrayList);
        this.context = context;
        this.titleArrayList = titleArrayList;
        this.descArrayList = descArrayList;
        this.timeArrayList = timeArrayList;
        this.imgArrayList = imgArrayList;
        this.IdArrayList = IdArrayList;
        this.data = data;
        this.layoutResID = layoutResourceId;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        final StockQuoteView sqView;

        if (rowView == null) {


            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            rowView = inflater.inflate(layoutResID, parent, false);
            sqView = new StockQuoteView();
            sqView.tag = (TextView) rowView.findViewById(R.id.tv_fullnote);

            sqView.desc = (TextView) rowView.findViewById(R.id.tv_title);
            sqView.time = (TextView) rowView.findViewById(R.id.tv_time);
            sqView.id = (TextView) rowView.findViewById(R.id.id);
            sqView.img = (ImageView) rowView.findViewById(R.id.imageView3);

            sqView.button1 = (ImageView) rowView.findViewById(R.id.swipe_button1);
            sqView.button2 = (ImageView) rowView.findViewById(R.id.swipe_button2);
            sqView.button3 = (ImageView) rowView.findViewById(R.id.swipe_button3);
            sqView.button4 = (ImageView) rowView.findViewById(R.id.swipe_button4);
            rowView.setTag(sqView);
        } else {
            sqView = (StockQuoteView) rowView.getTag();
        }

        try {
            sqView.tag.setText(titleArrayList.get(position));
            sqView.desc.setText(descArrayList.get(position));
            sqView.time.setText(timeArrayList.get(position));
            sqView.id.setText(IdArrayList.get(position));
            sqView.id.setTag(IdArrayList.get(position).toString());
            if (imgArrayList.get(position).contains("null")) {
                sqView.img.setImageBitmap(null);
                sqView.img.setTag("null");
            } else {
                myBitmap = BitmapFactory.decodeFile(imgArrayList.get(position));
                //sqView.img.setImageBitmap((position & 1) == 1 ? myBitmap : myBitmap);
                String TAG = "tag";
                String id = String.valueOf(position);

                sqView.img.setTag(imgArrayList.get(position).toString());
                int width = myBitmap.getWidth();
                int height = myBitmap.getHeight();
                int newWidth = (height > width) ? width : height;
                int newHeight = (height > width) ? height - (height - width) : height;
                int crop = (width - height) / 2;
                crop = (crop < 0) ? 0 : crop;
                Bitmap cropImg = Bitmap.createBitmap(myBitmap, crop, 0, newWidth, newHeight);
                sqView.img.setImageBitmap(cropImg);
            }
        } catch (Exception e) {
            System.out.print(e.toString());
        }


        return rowView;
    }

    protected static class StockQuoteView {
        protected TextView tag;
        protected TextView desc;
        protected TextView time;
        protected ImageView img;
        protected ImageView button1;
        protected ImageView button2;
        protected ImageView button3;
        protected ImageView button4;
        public TextView id;
    }


}
`

解决方案

put this linesqView.img.setVisibility(View.INVISIBLE) after sqView.img.setTag("null"); and Make Visible back the imageView in the else statment like else {sqView.img.setVisibility(View.VISIBLE) myBitmap = BitmapFactory.decodeFile(imgArrayList.get(position)); //sqView.img.setImageBitmap((position & 1) == 1 ? myBitmap : myBitmap); String TAG = "tag"; String id = String.valueOf(position);............} this is tricked only.

这篇关于列表视图改变在滚动的ImageView的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆