Open a web page when you click [Cotlin] and insert a page address variable

Asked 1 years ago, Updated 1 years ago, 85 views

I'm a beginner at Cotlin.

I'm currently using gson in the Cotlin project Getting the data from the DB server was successful I checked that it appears as a text in the Recycler view.

What I want to do is to access the link address from DB when I click on the view.

Currently, the address I want to connect to is printed well by println(user8.URI)

val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://naver.com")) I want to fill in the address instead of " but it doesn't work. NAVER opens well.

val intent = Intent(Intent.ACTION_VIEW, Uri.parse(user8.URI)) I thought it would work this way, but it didn't work, so I'm asking.

I don't know if it's because she's divided. I don't feel like a beginner. I'd appreciate your help.

class MainAdapter(var homeFeed: HomeFeed): RecyclerView.Adapter<CustomViewHolder>() {


    override fun getItemCount(): Int {
        return homeFeed.user8.count()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
        //How do we even create a view
        val layoutInflater = LayoutInflater.from(parent.context)
        val cellForRow = layoutInflater.inflate(R.layout.video_row, parent, false)
        return CustomViewHolder(cellForRow)
    }

    override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {

        val user8 = homeFeed.user8.get(position)
        holder?.view?.id_NAME.text = user8.NAME
        holder.view.id_TYPE.text = user8.TYPE
        holder.view.id_DATE.text = user8.DATE
        holder.view.id_PLACE.text = user8.PLACE
        holder.view.id_URI.text = user8.URI

        println(user8.URI)


    }

}

class CustomViewHolder(val view: View): RecyclerView.ViewHolder(view) {

    init {
        view.setOnClickListener {
            println("TEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
            val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://naver.com"))

            view.context.startActivity(intent)

        }
    }

}

kotlin listener gson json variable

2022-09-21 11:58

1 Answers

It may not work if you connect to http. Please use the https address or allow http access.

Related materials blog

And please write down how it doesn't work out.


2022-09-21 11:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.