Home > database >  Android how to clickable Addresses in TextView
Android how to clickable Addresses in TextView

Time:09-07

When there is any address in string, showing in TextView, need to be clickable and open on maps.

I've tried tv.setAutoLinkMask(Linkify.ALL). It is not working for all addresses. enter image description here

Any other way that's make clickable and link all addresses in TextView?

CodePudding user response:

you can use simple on click listener.

 textView.setOnClickListener {
 //open google maps

 }

and for text to make it look like a link you can use:

    <string name="underline_text"><![CDATA[<u>underlined text</u>]]></string>

Also, you can use blue text color (#0D6EFD) to make it more professional.

CodePudding user response:

you can use Intent.ACTION_VIEW to open google map from your app. Something like this:

    tv.setOnClickListener {
        val address = tv.text
        val content = "geo:0,0?q=$address"
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(content))
        startActivity(intent)
    }

Here I'm using Kotlin, convert java if you want

  • Related