2011-05-19 85 views
0

我正在修改Android記事本教程的版本。下面的代碼是從fillData功能基本上顯示錶屏幕上的所有筆記的標題,略作修改:將顯示設置添加到Android TextView

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"/> 

我怎樣才能將@+id/text1添加到此XML文件,以便當KEY_SPECIAL字段設置爲true(或1)時,TextView變粗體?如果我想使用CheckedTextView並獲得複選標記而不是粗體怎麼辦?如何編寫XML文件以查找該輸入以確定它是否最初被檢查?

回答

0

您將需要編寫自己的自定義適配器以根據僅在運行時已知的條件進行文本更改。簡單適配器適用於在每一行放置標題和副標題,但如果您需要的東西不止於此,則需要定製。

看看Android : BaseAdapter how to?