13

Guys I am trying to add large text with a website link like (https://stackoverflow.com/questions/ask) in my textview Located in database I tried adding it directly like this image :

picture of my value in databse

picture of my value in databse

But it appeared in the application on the form Textview not clickable like this image :

output app

output app

protected void onPostExecute(String result) {

        // Parse les données JSON
        String id;
        String solution;
        try {
            JSONArray jArray = new JSONArray(result);
            for (int i = 0; i < jArray.length(); i++) {
                JSONObject json_data = jArray.getJSONObject(i);
                id= json_data.getString("alltext");
                solution = json_data.getString("title");
                prob.setText(solution);
                sol.setText(id);
                // Résultats de la requête
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

    }
Community
  • 1
  • 1

2 Answers2

29

Set the AutoLink to web in TextView it will automatically detect the links

<TextView
    android:autoLink="web"
    android:text="This is Google http://www.google.com"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

enter image description here

Fahad Rehman
  • 1,189
  • 11
  • 25
12

First of All set the Text to TextView

lbl2.setText("hi http://google.com");
Linkify.addLinks(lbl2,Linkify.ALL);

Linkify automatically the clickable the link and other text remain same.

Arslan Maqbool
  • 519
  • 1
  • 7
  • 21