Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect website link in Textview and make it clickable [duplicate]

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());
        }

    }
like image 870
Mouad Abdelghafour AitAli Avatar asked Apr 13 '17 18:04

Mouad Abdelghafour AitAli


People also ask

Can I make a TextView clickable?

Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.

How do I use Linkify?

To call linkify in android, we have to call linkify. addLinks(), in that method we have to pass textview and LinkifyMask. Linkify. WEB_URLS: It going make URL as web url, when user click on it, it going to send url to default web browsers.

What is LinkMovementMethod?

android.text.method.LinkMovementMethod. A movement method that traverses links in the text buffer and scrolls if necessary. Supports clicking on links with DPad Center or Enter.


1 Answers

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

like image 107
Fahad Rehman Avatar answered Nov 15 '22 19:11

Fahad Rehman