【发布时间】:2014-06-04 10:34:55
【问题描述】:
我正在尝试在对话框中显示 HTML 代码,但 HTML 需要存储在一个字符串中,该字符串首先放入 textview。
我发现了许多其他类似的问题,但大多数是在代码中而不是在 strings.xml 中设置文本。没有我发现似乎使用“对话框到 textview 到字符串与 html”过程。 到目前为止,我已经完成了我认为应该有效的工作,但我现在遇到了错误(如下)。我尝试了其他方法,但无法显示 HTML 效果。
我还是 Android 新手,所以如果能帮我看看我做错了什么,那就太好了。谢谢。
preferencesActivity.java - OnCreate
Preference myPref = (Preference) findPreference("pref_showHelp");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Dialog dialog = new dialog(preferencesActivity.this);
helpFile_textView = (TextView) findViewById(R.id.helpFile_textView);
helpFile_textView.setText(Html.fromHtml(getString(R.string.helpFile_text))); // Line 44
dialog.setContentView(R.layout.helpfile);
dialog.setTitle("Help");
dialog.show();
return false;
}
});
}
帮助文件.xml
<TextView
android:id="@+id/helpFile_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/helpFile_text" />
</LinearLayout>
字符串 .xml
<string name="helpFile_text">Test of <b>bold and <u>underline</u> and bullet •</string>
Logcat
E/AndroidRuntime(1516): java.lang.NullPointerException
E/AndroidRuntime(1516): at com.example.newcalc.preferencesActivity$1.onPreferenceClick(preferencesActivity.java:44)
【问题讨论】:
标签: android html dialog textview