如何将超链接设置为单击此处的链接的文本,整个文本主体来自android中静态json的字符串

时间:2018-07-04 08:22:21

标签: android json hyperlink

{
  "json_pos": "11",
  "beach_name": "Kee (Haena State Park)",
  "direction": "N",
  "code_name": "Lifeguarded",
  "pin": "pingreen",
  "about": "ALERT: Haena State Park is closed until further notice due to April 2018 floods, as is the Kalalau trail. There is a master plan in place for developing the park–more information on both at http://dlnr.hawaii.gov/dsp/parks/kauai/haena-state-park \n\nThe last beach on the north shore, Kee is one of the loveliest on the island. This magical lagoon is Hawaii personified, and a 'must see'.\n\nThe lagoon is great for swimming, and pretty good for snorkeling when conditions are calm. Under rougher conditions, the lifeguards will use their bullhorn to call people in from the channel on the left side of the lagoon, as the current can pull people out to sea. If conditions are rough, the lifeguards will close the beach first for snorkeling, and then even for swimming.\n\nTake a short walk on the beach to the right (keeping the lagoon on your left) to see incredible views down the Na Pali coastline. This coastline is one of Kauai's highlights and this will be your only view of it, unless you hike the Kalalau trail, take a boat, or a helicopter ride. In the summer there are wonderful sunset views to be seen from here. Trees along the beach provide ample shade except in the late afternoon.",
  "about_short": "The last beach on the north shore, Kee is one of the loveliest on the island.",
  "short_description": "",
  "full_description": "",
  "info_image": "",
   "gmap_lat": "22.220411",
  "gmap_long": "-159.582552",
  "ad_text": "Holo Holo Charters",
  "ad_url": "",
  "ad_image": "",
  "facilities": [
    [
      'lifeguard',
      'restrooms',
      'showers',
      'child_friendly_beach'
    ]
  ],
  "gallery_images_prefix": "kee",
  "bodyboarding": "",
  "swimming": "Protected by reef, the lagoon is a great place to swim. It is one of the calmest beaches on the north shore during summer months (May-Sept). Be aware of the channel on the far left as the current can pull people out to sea. The entry is shallow, and relatively easy to get in and out of the water. The reef to the right is obvious, and the water is too shallow to swim over it.\n\nUnder rough conditions, the lifeguards will use their bullhorn to call people in from the channel on the left side of the lagoon, as the current can pull people out to sea. If the conditions are dangerous, the lifeguards will close the beach for swimming.",
  "snorkeling": "As with any beach, snorkeling is best when the waves are 0-2ft. Remember, always check for current conditions.  The right side of the lagoon is better snorkeling. Slowly snorkel up the side of the reef, staying clear of the channel. There are a number of colorful reef fish to be seen here. Avoid swimming over the reef itself as the water can be too shallow.\n\nUnder rough conditions, the lifeguards will use their bullhorn to call people in from the channel on the left side of the lagoon, as the current can pull people out to sea. If the conditions are dangerous, the lifeguards will close the beach for snorkeling.",
  "hiking": "Here you’ll find the start of the Kalalau trail. This hike into Kalalau is 11 miles long, and rated a 9 out of 10 for difficulty by the Sierra Club. It is possible to hike the first two miles to Hanakapiai beach, and another two mile up to Hanakapiai waterfall without a permit.\n\nThe trail from Kee climbs quickly, is rugged, slippery when wet, and has incredible views. Even going the first 1/2 mile has its rewards.\n\nTwo miles brings you to Hanakapiai beach, which is the most dangerous beach on Kauai. Swimming is not recommended due to very strong currents, and there have been a number of drownings here.\n\nUse caution crossing all streams. Waters can rise quickly during bad weather. It's better to stay a night on the trail waiting for the waters to recede, than to cross fast-flowing waters that might sweep you out to sea.\n\nGood shoes and plenty of water are a must. For more information go to: http://dlnr.hawaii.gov/dsp/hiking/kauai/kalalau-trail",
  "hazards": "When surf is over 2 ft. a current is created that flows in over the reef, and flows out of the channel on the left side of the lagoon, closest to the cliffs. The rip current can be very strong, and does pull people out to sea. Lifeguards will close the beach under hazardous conditions such as high surf; this is for your safety.\n\nConditions are especially dangerous October-April.\n\nMany people use this as a starting point to hike the Na Pali Coastline. It is best to not swim in the ocean at all along this trail. Hanakapiai beach, 2 miles in on the Na Pali trail, is the most dangerous beach on the island. Kalalau beach at the end of the trail has a dangerous shorebreak.",
  "parking": "Summer is especially crowded, and parking can be a challenge. Our recommendation is to drive to the end of the road, drop off everyone and their gear, and then go back to park your car. Depending on the number of cars you might wind up in the back-up lot 1/4 mile up the road, or even on the side of the road if it's very busy.\n\nPay attention to 'No Parking' signs along the road as the police do ticket now and again.",
  "history": "Many remember this beautiful lagoon from the romantic love scene in the TV miniseries 'The Thornbirds', but this area includes an extremely sacred and private historical site still in use today.  The Ka-ulu-o-Laka heiau is dedicated to the hula goddess Laka, who it is said began hula at this site. Hula dancers and chanters from all over the Hawaiian Islands came here to train.\n\nAround the corner to the right near the stream was where Taylor Camp existed from 1968  -  1977. Elizabeth Taylor's brother Howard owned the property, and opened it up to hippies. They moved in, built tree houses, and are said to have begun the Puka shell craze by giving a handmade necklace to Howard, who gave it to his famous sister, and the rest as they say, is history."
}

此json字符串主体中的“大约部分”在textview中显示,但我需要在单击此处文本内插入此链接-http://dlnr.hawaii.gov/dsp/parks/kauai/haena-state-park,简而言之,以上链接将由单击此处文本替换,我应该如何做到

2 个答案:

答案 0 :(得分:0)

Use a SpannableStringBuilder and make that as a hyperlink when the string contains that http:// as a part of the sentence and replace the full word with the word click here and add a clickablespan so that u can make it clickable

SpannableString ss = new SpannableString("Android is a Software stack");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        startActivity(new Intent(MyActivity.this, NextActivity.class));
    }
    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }
};
ss.setSpan(clickableSpan, 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);

答案 1 :(得分:0)

尝试

  

about是您的原始字符串。

   Url= about.substring(string.indexOf("https://"),string.indexOf(' ',string.indexOf("https://")));

   int positon=string.indexOf(' ',string.indexOf("https://")); // URL ending position

    ClickableSpan myClickableSpan = new ClickableSpan() {
                    @Override
                    public void onClick(View widget) {
                        // Use Url
                       // Your click logic with link
                    }

                    @Override
                    public void updateDrawState(TextPaint ds) {
                        super.updateDrawState(ds);
                    }
                };

     SpannableStringBuilder builder = new SpannableStringBuilder();
     builder.append(about.substring(0,about.indexof("https://"))).append(" Click Here ", myClickableSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE).append(about.substring(position));

     TextView textView = (TextView) findViewById(R.id.hello);
     textView.setText(builder, TextView.BufferType.SPANNABLE);
     textView.setMovementMethod(LinkMovementMethod.getInstance());