2013-07-24 98 views
2

我的應用程序從在線服務器檢索數據。如果我在應用程序中插入像Hello這樣的服務器,如果你點擊上面,不要帶領任何地方。爲什麼?這是源與java的href鏈接

MyText = (TextView) this.findViewById(R.art.tit); 
     Text = (TextView) this.findViewById(R.artic.text); 
     String formattedText = db.getTesto(); 
     String formattedTitle = db.getTitolo(); 
     MyText.setText(Html.fromHtml(formattedTitle)); 
     Text.setText(Html.fromHtml(formattedText)); 
+0

http://android-developers.blogspot.in/2008/03/linkify-your-text.html。鏈接你的文字。 – Raghunandan

回答

0

這是超鏈接的示例:

MyText = (TextView) this.findViewById(R.art.tit); 
Text = (TextView) this.findViewById(R.artic.text); 
tv1.setLayoutParams(textOutLayoutParams); 
tv1.setText(Html.fromHtml("<a href=\""+ formattedText + "\">" + formattedTitle + "</a>")); 
tv1.setClickable(true); 
tv1.setMovementMethod (LinkMovementMethod.getInstance()); 
dialogLayout.addView(tv1); 
0

我終於得到它的工作使用下面的代碼:

TextView tv1 = new TextView(this); 
tv1.setLayoutParams(textOutLayoutParams); 
tv1.setText(Html.fromHtml("<a href=\""+ l.getRightString() + "\">" + l.getLeftString() + "</a>")); 
tv1.setClickable(true); 
tv1.setMovementMethod (LinkMovementMethod.getInstance()); 
dialogLayout.addView(tv1); 

l.getRightString() - 包含像網址: http:\www.google.com
l.getLeftString() - 包含以下網址的文本:"Go to Google"

結果:我的對話框中的文字爲「轉到Google」,並帶有藍色並加下劃線,點擊它後瀏覽器打開並顯示相應的頁面。
在返回/退出瀏覽器時,它再次從應用程序離開的狀態進入應用程序。

希望這會有所幫助。

0

在Android中,你可以通過兩種方式添加鏈接, - 在XML設計android:autoLink="web"爲TextView的它會帶你到web瀏覽器的onclick - 如果你想在代碼中添加你可以添加像

TextView yourTextview= (TextView) findViewById(R.id.noteview); yourTextview.setText(youURL link); Linkify.addLinks(yourTextview, Linkify.ALL);

謝謝。