I want to get the string from urldata.url to put into Uri.parse so when I click it will take me to the webpage of that url
the code itself works fine but only the URI parse can't get the string from urldata
override fun onBindViewHolder(holder: adapter.MyViewHolder, position: Int)
{
val urldata : data = datalist[position]
holder.name.text = urldata.name
holder.url.text = urldata.url
// cardview clicking link to the url
holder.itemView.setOnClickListener(
View.OnClickListener {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse()
)
)
}
)
}
any suggestion?
CodePudding user response:
Uri uri = Uri.parse(urldata.url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Try adding this onClickListener
CodePudding user response:
Try to change your setOnClickListener
like this:
holder.itemView.setOnClickListener {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(urldata.url)
)
)
} catch (e: ParseException) { Log.e("onBindViewHolder", "Invalid URI") }
}