【发布时间】:2018-06-24 03:46:16
【问题描述】:
我有一个包含多个选项卡的活动,每个选项卡都包含一个片段,其中包含一些文本。我想要一个带有“阅读更多”的文本,它是一个 URL 的链接。没有链接,一切正常,但是当我尝试实现它时,我得到了
E/UncaughtException: java.lang.NullPointerException
所以我认为这是我实现它的方式。现在,片段有这个:
public class About_us extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_about_us, container, false);
//The part below is For Read More
TextView t2 = (TextView) getView().findViewById(R.id.read_more);
if (t2 != null) {
t2.setMovementMethod(LinkMovementMethod.getInstance());
}
return rootView;
}
}
"read_more" 布局对于 TextView 有这个:
< TextView
android: id = "@+id/read_more"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: clickable = "true"
android: text = "@string/link_to_the_website"
android: textColor = "@color/buttonColorPressed" / >
并且在字符串中给出了link_to_website:
< string name = "link_to_the_website" > < a href = "www.google.com/" > Read More Here < /a></string >
谁能帮我弄清楚我写错了什么?
【问题讨论】:
标签: android android-fragments url hyperlink