Android API之CheckedTextView代码演示


类CheckedTextView继承超类TextView并实现Checkable接口。当ListView的setChoiceMode方法并设定为CHOICE_MODE_SINGLE或者CHOICE_MODE_MULTIPLE,而非CHOICE_MODE_NONE时,使用此类是很有用的。

使用范例:

(1)

/res/layout/main.xml 中添加相应资源ID

<ListView

    Android:id="@+id/listView"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    />

    <CheckedTextView

    android:id="@+id/checkedTextView1"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:checkMark="?android:attr/listChoiceIndicatorMultiple"

    android:text="@string/checkedTextView1"

    />

    <CheckedTextView

    android:id="@+id/checkedTextView2"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:checkMark="?android:attr/listChoiceIndicatorMultiple"

    android:text="@string/checkedTextView2"

    />

  

    <CheckedTextView

    android:id="@+id/checkedTextView3"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:checkMark="?android:attr/listChoiceIndicatorMultiple"

    android:text="@string/checkedTextView3"

    />

    <CheckedTextView

    android:id="@+id/checkedTextView4"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:checkMark="?android:attr/listChoiceIndicatorMultiple"

    android:text="@string/checkedTextView4"

/>

(2)/res/values/strings.xml 资源

<string name="hello">TextView多选框</string>

    <string name="app_name">CheckedTextView</string>

    <string name="checkedTextView1">TextView多选框1</string>

    <string name="checkedTextView2">TextView多选框2</string>

    <string name="checkedTextView3">TextView多选框3</string>

    <string name="checkedTextView4">TextView多选框4</string>

  • 1
  • 2
  • 下一页

相关内容