2

I've programmatically created TextView and then set data in it. But I'm not able to detect the links inside the data.

This is the code:

TextView dataView = new TextView(this);
dataView.setLayoutParams(dataParams);
dataView.setText("www.google.com");

I've tried with the : dataView.setMovementMethod(LinkMovementMethod.getInstance()); and

dataView.setLinksClickable(true);

but it doesn't works for me.

It will be great if anyone can help me here. Thanks in advance.

Prithniraj Nicyone
  • 5,021
  • 13
  • 52
  • 78

3 Answers3

1

Try this

    Linkify.addLinks(dataView, Linkify.WEB_URLS);
    dataView.setLinksClickable(true);
Nitesh
  • 3,868
  • 1
  • 20
  • 26
0

Try This:

dataView.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {
    TextView tv = (TextView)v;
    String link = tv.getText().toString();
  }

};);
Amy
  • 4,034
  • 1
  • 20
  • 34
0
TextView dataView = new TextView(this);
       dataView.setLayoutParams(dataParams);
       dataView.setText( Html.fromHtml("<b><a style='text-color:white;' href='"+"http://www.google.com"+"'>Google</a></b>"));
       dataView. setMovementMethod(LinkMovementMethod.getInstance());
Raghavendra B
  • 441
  • 3
  • 10