1

Possible Duplicate:
How do I make links in a TextView clickable?

I've a FragmentActivity with three fragments. I've a separate class for each fragment in which i build the fragments view.

In this process I create several clickable textview with a weblink. It seems everything is correct and the textviews appears clickable. But nothing happens when I click on a textview.

Why does nothing happen onTextViewClick? I would expect to see a list of browser where the link could be opened.

I found a lot of similar questions but couldn't find a mistake in my code so far. Similar questions:

Here is my code of the LinksFragment. A instance of the class is created on the FragmentActivity itself to display this fragment:

public class LinksFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return generateView(inflater, container); 
    }

    private View generateView(LayoutInflater inflater, ViewGroup container){

        // inflate layout
        View view = inflater.inflate(R.layout.fragment_links, container, false);

        // find controls
        LinearLayout list = (LinearLayout) view.findViewById(R.id.fragment_links_list);

        // generate list
        String[] links = getActivity().getApplicationContext().getResources().getStringArray(R.array.links);
        for (int i = 0; i < links.length; i++) {
            list.addView(generateClickableTextView(links[i]));
        }

        return view;
    }

    private TextView generateClickableTextView(String text){
        TextView clickableTextView = new TextView(getActivity());       
        clickableTextView.setMovementMethod(LinkMovementMethod.getInstance());
        clickableTextView.setText(Html.fromHtml(text));
        return clickableTextView;
    }
}

And the links Array:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="links">
        <item><a href="http://www.google.com">- Google</a></item>
        <item><a href="http://www.bing.com">- Bing</a></item>
        <item><a href="http://www.yahoo.com">- Yahoo</a></item>
        <item><a href="http://www.youtube.com">- Youtube</a></item>
        <item><a href="http://www.Vimeo.com">- Vimeo</a></item>
    </string-array>
</resources>

EDIT Solution:

The solution to my problem was in this post:

https://stackoverflow.com/a/10125089/1306012

I just had to replace all "<" with "&lt ;" (without the space)

Thanks to https://stackoverflow.com/users/634474/dymmeh to direct me to this post.

Community
  • 1
  • 1
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
  • 1
    Check out this answer in regard to putting links in a resource file: http://stackoverflow.com/a/10125089/634474 – dymmeh Nov 19 '12 at 14:07

0 Answers0