2017-04-13 85 views
0

傢伙我試圖與網站link在我textview位於數據庫 我嘗試添加它直接像這樣的圖像添加大量的文字像(https://stackoverflow.com/questions/ask):如何檢測網站鏈接的TextView並使其可點擊

在DATABSE

picture of my value in databse

我的價值的照片,但它出現在應用程序的形式Textview不可點擊這樣的形象:

輸出應用

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

    } 

回答

2

設置AutoLinkwebTextView它會自動檢測環節

<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

+0

非常感謝,請給我另一個問題,我想讓超鏈接例如:(http://www.youtube.com)取代它只是Youtube –

+0

使用此代碼爲超鏈接文本 'TextView textView = (的TextView)findViewById(R.id.textView); textView.setClickable(真); textView.setMovementMethod(LinkMovementMethod.getInstance()); String text =「 Google」; textView.setText(Html.fromHtml(text));' –

+0

工作。謝謝。 –

4

的所有第一文本設置爲TextView的

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

Linkify自動可點擊的鏈接和其他文本保持不變。

+0

非常感謝,幫助我:) –

+0

我的榮幸:)標記,如果它真的幫助你。 –

相關問題