【问题标题】:need help opening url from adapter kotlin需要帮助从适配器 kotlin 打开 url
【发布时间】:2020-10-07 16:49:02
【问题描述】:

我需要打开一个我从数据库中提取的项目并在浏览器中打开它的 url。

但它没有打开,但如果我在 onclicklistener 中尝试不同的代码,它会运行它,但是当我尝试打开 url 时它没有这样做

class ItemHolder(itemView: View): RecyclerView.ViewHolder(itemView)
{
    fun bind(n: String, p: Double, u: String, item_id: Int)
    {
        itemView.item_name.text=n
        itemView.item_price.text=p.toString()
        var web:String=""+u
        web=web.replace(" ", "%20")
        Picasso.with(itemView.context).load(web).into(itemView.item_photo)

        itemView.view_browers.setOnClickListener {
            val context: Context? = null

            val url = "http://www.example.com"
            context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))


        }

    }
}

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    您将context 设置为空,所以该行

    context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
    

    什么都不做。

    您需要使用非空上下文。向我们展示有效的代码,我们可以对其进行修改,使其符合您的要求。

    【讨论】:

      猜你喜欢
      • 2017-06-03
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      相关资源
      最近更新 更多