android中的光标适配器滚动列表时填充错误的图像

发布于 2024-10-07 03:06:29 字数 2490 浏览 0 评论 0原文

我的光标适配器有问题,我有自定义适配器,其中有图像、文本、复选框,一切正常,但当我滚动包含 30 个项目的列表时,一些图像混乱,文本显示正常。

问题是什么,我必须修复任何属性或更改实现,只要我的图像来自从数据库获取的光标。

代码是:

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return super.getView(position, convertView, parent);
        }

        @Override
        public void bindView(View view, Context context, final Cursor cursor) {


            Image = (ImageView) view.findViewById(R.id.CoverArtImage);
            byte[] theByteArray = cursor.getBlob(4);
            if (theByteArray != null) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(theByteArray, 0,
                        theByteArray.length);
                Image.setImageBitmap(bitmap);
                bitmap = null;
                theByteArray = null;
            }

            tText = (TextView) view.findViewById(R.id.TrackTextView);
            tText.setText(cursor.getString(2));

            aText = (TextView) view.findViewById(R.id.ArtistTextView);
            aText.setText(cursor.getString(3));

            aText = (TextView) view.findViewById(R.id.AlbumTextView);
            aText.setText(cursor.getString(1));

            dateText = (TextView) view.findViewById(R.id.DateTimeTextView);
            dateText.setText(cursor.getString(5));

            deletecheckBox.setTag(cursor.getString(0));
            deletecheckBox.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    CheckBox chk = (CheckBox) v;
                    if (chk.isChecked()) {
                        deleteId.add(chk.getTag().toString());
                        // System.out.println("Chaked......" + chk.getTag());
                    } else {
                        deleteId.remove(chk.getTag().toString());
                        // System.out.println("UnChaked......" + chk.getTag());
                    }
                }
            });
        }

        @Override
        public View newView(Context context, final Cursor cursor,
                ViewGroup parent) {
            final View view = mInflater.inflate(R.layout.histrory_row, parent,
                    false);
            view.setOnClickListener(HistoryDetails.this);
            view.setTag(cursor.getString(0));
            deletecheckBox = (CheckBox) view.findViewById(R.id.DeleteCheckbox);
            bindView(view, context, cursor);
            return view;
        }

谢谢

I have problem with cursor adapter, i have custom adapter in which there is image,text,check box, all works fine but as an when i scroll list with 30 item some images disarrange and text show fine.

what is the problem, i have to fix any property or change implementation all time my image come from cursor which fetch from databases.

code is :

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return super.getView(position, convertView, parent);
        }

        @Override
        public void bindView(View view, Context context, final Cursor cursor) {


            Image = (ImageView) view.findViewById(R.id.CoverArtImage);
            byte[] theByteArray = cursor.getBlob(4);
            if (theByteArray != null) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(theByteArray, 0,
                        theByteArray.length);
                Image.setImageBitmap(bitmap);
                bitmap = null;
                theByteArray = null;
            }

            tText = (TextView) view.findViewById(R.id.TrackTextView);
            tText.setText(cursor.getString(2));

            aText = (TextView) view.findViewById(R.id.ArtistTextView);
            aText.setText(cursor.getString(3));

            aText = (TextView) view.findViewById(R.id.AlbumTextView);
            aText.setText(cursor.getString(1));

            dateText = (TextView) view.findViewById(R.id.DateTimeTextView);
            dateText.setText(cursor.getString(5));

            deletecheckBox.setTag(cursor.getString(0));
            deletecheckBox.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    CheckBox chk = (CheckBox) v;
                    if (chk.isChecked()) {
                        deleteId.add(chk.getTag().toString());
                        // System.out.println("Chaked......" + chk.getTag());
                    } else {
                        deleteId.remove(chk.getTag().toString());
                        // System.out.println("UnChaked......" + chk.getTag());
                    }
                }
            });
        }

        @Override
        public View newView(Context context, final Cursor cursor,
                ViewGroup parent) {
            final View view = mInflater.inflate(R.layout.histrory_row, parent,
                    false);
            view.setOnClickListener(HistoryDetails.this);
            view.setTag(cursor.getString(0));
            deletecheckBox = (CheckBox) view.findViewById(R.id.DeleteCheckbox);
            bindView(view, context, cursor);
            return view;
        }

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文