为 Android TextView 添加显示设置
我正在开发 Android 记事本教程的修改版本。以下代码来自 fillData 函数,该函数基本上在表格屏幕上显示所有笔记的标题,稍作修改:
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
String[] from = new String[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_SPECIAL};
int[] to = new int[]{R.id.text1, R.id.text2};
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
notes_row.xml
文件非常简单:
<TextView
android:id="@+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
How can I add @ +id/text1
到此 XML 文件,以便当KEY_SPECIAL
字段设置为 true(或 1)时,TextView 会加粗?如果我想使用 CheckedTextView 并获取复选标记而不是粗体怎么办?如何编写 XML 文件来查找该输入以确定它是否最初经过检查?
I'm working on a modified version of the Android Notepad tutorial. The following code is from the fillData function which basically displays the titles of all the notes on a table screen, slightly modified:
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
String[] from = new String[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_SPECIAL};
int[] to = new int[]{R.id.text1, R.id.text2};
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
The notes_row.xml
file, is very simple:
<TextView
android:id="@+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
How can I add @+id/text1
to this XML file so that when the KEY_SPECIAL
field is set to true (or 1), the TextView is bolded? What if I want to use CheckedTextView and get the checkmark instead of bold? How do I write the XML file to look for that input to determine if it's checked originally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要编写自己的自定义适配器,以便根据仅在运行时已知的条件来更改文本。简单适配器用于在每一行上放置标题和副标题,但如果您需要更多内容,则需要自定义。
查看Android:BaseAdapter 如何操作?。
You will need to write your own custom adapter to have text change based on conditions that are only known at runtime. The Simple adapters work for putting a title and subtitle on every row, but if you need anything more than that you need to go custom.
Take a look at Android : BaseAdapter how to?.