Loading image from URL in custom adapter for ListView (Android Studio)

前端 未结 2 1087
粉色の甜心
粉色の甜心 2021-01-06 09:48

While the bitmap seems to be fetched right, the variable \'userBitmap\' will remain null. When scrolling up or down on my tablet, though, new list rows will contain the pic

2条回答
  •  温柔的废话
    2021-01-06 10:34

    The easiest way to solve your problem is using some library, for example Picasso. It is not only easier to use and make your code easier to read, but also prevents you from OutOfMemory Exceptions, when images are too big. Loading image is then matter of one line:

    Picasso.with(context)
    .load(urlOfYourImage)
    .resize(50, 50) // here you resize your image to whatever width and height you like
    .into(imageView)
    

提交回复
热议问题