android Picasso未在第二个Activity中从URL加载图像

fiei3ece  于 2023-05-12  发布在  Android
关注(0)|答案(2)|浏览(98)

我尝试将图像从第一个Activity加载到第二个Activity,方法是通过Intent传递图像,然后使用Picasso加载图像。然而,即使intent工作并且url在那里,图像也没有加载,我不知道为什么。这是第二个活动:

class PostActivity: AppCompatActivity() {

    private lateinit var binding: ActivityPostBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_post)
        binding = ActivityPostBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)

        //get title
        val detailTitle = intent.getStringExtra("NEWS_TITLE")
        binding.tvTitleItem.text = detailTitle

        //get image
        val detailImage = intent.getStringExtra("NEWS_IMAGE")
        Picasso.get().load(detailImage).into(binding.ivNewsImageDetail)

        binding.ivNewsImageDetail.setOnClickListener {
            Log.d("IMAGE","$detailImage")
        }

通过setOnClickListener,我知道url在那里,但spot是空的。有什么想法是不工作的吗?

jogvjijk

jogvjijk1#

我想可能是装订没有完全装上。试试这个

binding.ivNewsImageDetail.post { 
   //get image
   val detailImage = intent.getStringExtra("NEWS_IMAGE")
   Picasso.get().load(detailImage).into(binding.ivNewsImageDetail)
}
cwxwcias

cwxwcias2#

try {
        Picasso.with(this).load(ImageUrl).into(imageView)
    } catch (ex: Exception) {

}

相关问题