开发者

Android linkify an address without displaying the full address

So I'm writing an app for a specific area where the user really doesn't need to see the full address. I want to开发者_JAVA百科 turn a textview into a map address link, but don't want to have to explicitly type the full address.

Pretty simple, I only want to display the address number and street name, but leave the city, state, and zip out. Does anyone know how I can do this? Here's a chunk of my code.

textView.setText(towedVehicle.getAddress());
Linkify.addLinks(textView, Linkify.MAP_ADDRESSES);


After a little searching I was able to solve it pretty easily

Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=address+of+location")); 
startActivity(searchAddress); 

I made the textview clickable and underlined it to look like a normal link.

SpannableString towedToAddress = new SpannableString(towedVehicle.getTowedToAddress());
            towedToAddress.setSpan(new UnderlineSpan(), 0,towedToAddress.length(), 0);
            towedToAddress.setSpan(new ForegroundColorSpan(0x990000FF), 0, towedToAddress.length(), 0);
            textView.setText(towedToAddress);
            textView.setClickable(true);

Opens up in Google maps and works great.


You should be able to do this using Transformfilters in the addLinks method. For an example please check this link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜