我的CheckedTextView中没有显示我的复选框

gre*_*egm 22 android

以下是我设置选中文本视图的方法.怎么没有复选框出现?

我也添加了这个但它没有效果:listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

 <CheckedTextView
 android:id="@+id/ctv_checktext"
 android:layout_width="fill_parent"
 android:paddingLeft="2px"
 android:paddingRight="2px"
 android:paddingTop="2px"
 android:layout_height="wrap_content"
 />
Run Code Online (Sandbox Code Playgroud)

gre*_*egm 52

(我正在回答我自己的问题,因为它在Android API中没有记录)

这还不够:

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Run Code Online (Sandbox Code Playgroud)

你需要包含android:checkMark ="?android:attr/listChoiceIndicatorMultiple"或者其他

 <CheckedTextView
 android:id="@+id/ctv_checktext"
 android:layout_width="fill_parent"
 android:paddingLeft="2px"
 android:paddingRight="2px"
 android:paddingTop="2px"
 android:layout_height="wrap_content"
 android:checkMark="?android:attr/listChoiceIndicatorMultiple"
 />
Run Code Online (Sandbox Code Playgroud)

  • CheckedEditText文档定义了[相关方法](http://developer.android.com/reference/android/widget/CheckedTextView.html#attr_android:checkMark).对于这个例子:`checkedEditText.setCheckMarkDrawable(android.R.attr.listChoiceIndicatorMultiple);` (2认同)