2013-07-24 94 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);

谢谢。