【发布时间】:2014-12-04 22:02:05
【问题描述】:
我创建了一个在滚动视图中包含相对布局的 android 应用程序,但无法使我在 textview 中的链接可点击。为了解决这个问题,我正在使用
TextView TextView = (TextView)findViewById(R.id.textview2);
TextView.setMovementMethod(LinkMovementMethod.getinstance());
所以,我知道 findViewById() 只会返回第一个实例。例如,如果我希望 textView2、textView4 和 textView8 都成为链接,我该怎么办。我假设这里的 for 循环可以解决问题?
【问题讨论】:
-
我没有看到问题。这些 TextView 中的每一个都不会有唯一的 ID 吗?因此,您只需为每个调用 findViewById 即可。例如TextView TextView4 = (TextView)findViewById(R.id.textview4);
-
findViewById() will only ever return the first instance。只有一个实例。 R.id.xxxx 是唯一的。 -
下面的行是 'TextView4.setMovementMethod(..)' 对吗?我可以做到这一点,我会为大约 300 个 textViews 做这件事,但是
-
好的,我明白了问题所在,以及为什么循环是有益的。我有几个想法。我会在一分钟内发布答案...
-
谢谢--我期待明天早上看到它(前往另一个办公室过夜)
标签: android textview findviewbyid linkify