J'ai ce code qui fonctionne pour ma méthode qui appelle un EditText, j'ai essayé d'utiliser le même code pour un TextView mais cela ne fonctionne pas. Le texte ne se transforme pas en un lien hypertexte comme dans EditText, est-ce que quelqu'un sait pourquoi?Est-ce que Linkify fonctionne pour TextView sous Android?
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.link_view);
// make sure that setText call comes BEFORE Linkify.addLinks call
tv.setText(tv.getText().toString());
Linkify.addLinks(tv, Linkify.WEB_URLS);
}}
Voici la mise en page:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:id="@+id/link_lbl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dip"
android:text="Link" />
<TextView
android:id="@+id/link_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="google.com" />
</TableRow>
</TableLayout>
Cela fonctionne bien dans EditText, j'ai juste besoin aider à faire la même chose dans TextView
http://developer.android.com/reference/android/text/util/Linkify.html – Raghunandan