Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 使用SimpleCursorAdapter和ViewBinder在ListView项目中设置图像大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在ListView中将图像设置为 ImageView?在这里,我使用SimplecursorAdapter显示所有字段,并使用ViewBinder将图像位图设置为ImageView.使用AsyncTask下载映像.我写的代码如下:

private void updatetiR_327_11845@elineUI() {
        cursor data = dbHelper.query(Constants.TABLE_NAME,null,null);
        if (data.moveToFirst()) {
            adapter = new SimplecursorAdapter(this,R.layout.tweet_row,data,new String[] {Constants.CREATED_TIME,Constants.username,Constants.PROFILE_IMAGE,Constants.TWEET},new int[] {R.id.time,R.id.username,R.id.userImageView,R.id.tweetmessagE});
            SimplecursorAdapter.ViewBinder viewBinder = new SimplecursorAdapter.ViewBinder() {
                public Boolean setViewValue(View view,cursor cursor,int columnIndeX) {
                    if(view != null && view.getId() != R.id.userImageView) {
                        return false;
                    }
                String imageUrlString = cursor.getString(columnIndeX);
                String username = cursor.getString(cursor.getcolumnIndex(Constants.username));
                String path = getDir("images",MODE_PRIVATE).getAbsolutePath() + "/" + username + ".png";
                ImageDownloader downloader = new ImageDownloader();
                downloader.setImageUrlString(imageUrlString);
                downloader.setImageView(view);
                downloader.setFilePath(path);
                downloader.execute(imageUrlString);
                return true;
                }
            };
            int index = data.getcolumnIndex(Constants.PROFILE_IMAGE);
            //Log.d(Constants.TAG,"" + indeX);
            adapter.setViewBinder(viewBinder);
            viewBinder.setViewValue(userImageView,indeX);
            timelineList.setAdapter(adapter);
        }
    }

有没有办法用这种方法将图像设置为正确的行?

使用我目前拥有的代码,可以成功下载图像.但是,图像是随机设置的.

解决方法

您应该创建自己的适配器,该适配器将继承自SimplecursorAdapter,因此您可以使用自定义设计制作自己的ListView项目,并为其设置自定义布局,您可以在其中添加所需的任何Ui元素,包括ImageView

大佬总结

以上是大佬教程为你收集整理的android – 使用SimpleCursorAdapter和ViewBinder在ListView项目中设置图像全部内容,希望文章能够帮你解决android – 使用SimpleCursorAdapter和ViewBinder在ListView项目中设置图像所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。