test

public View getView(int position, View convertView, ViewGroup parent) {
            View view = View.inflate(MyReadActivity.this, R.layout.book_item,
                    null);
            final ImageView iv_book = (ImageView) view
                    .findViewById(R.id.book_img);
            RatingBar rb = (RatingBar) view.findViewById(R.id.ratingbar);
            TextView tv_title = (TextView) view.findViewById(R.id.book_title);
            TextView tv_description = (TextView) view
                    .findViewById(R.id.book_description);
            Book book = books.get(position);
            if (book.getRating() != 0) {
                rb.setRating(book.getRating());
            } else {
                rb.setVisibility(View.INVISIBLE);
            }
            tv_description.setText(book.getDescription());
            tv_title.setText(book.getName());
           
            // 判断 图片是否在sd卡上存在
            String iconpath = book.getBookurl();
            final String iconname = iconpath.substring(
                    iconpath.lastIndexOf("/") + 1, iconpath.length());
            File file = new File("/sdcard/" + iconname);
            if (file.exists()) {
                iv_book.setImageURI(Uri.fromFile(file));
                System.out.println("使用sd卡缓存");
            } else {

                if (iconCache.containsKey(iconname)) {
                    SoftReference<Bitmap> softref = iconCache.get(iconname);
                    if (softref != null) {
                        Bitmap bitmap = softref.get();
                        if (bitmap != null) {
                            System.out.println("使用内存缓存 ");
                            iv_book.setImageBitmap(bitmap);
                        } else {
                            loadimage(iv_book, book, iconname);
                        }

                    }

                } else {

                    loadimage(iv_book, book, iconname);
                }
            }
            return view;
        }

你可能感兴趣的:(test)