CheckedTextView

译者署名:easy

译者博客:http://blog.sina.com.cn/xjtuyi

版本:Android 2.2 r1

 

public class CheckedTextView extends TextView implements Checkable

 

java.lang.Object

         android.view.View

                android.widget.TextView

                            android.widget.CheckedTextView

 

概述

    

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

 

公共方法       

public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

在子视图的构建时分派一个辅助事件。(译者注:通过源码可以看出,视图构建时设置其选中状态。)

参数

event       事件

返回值

   如果事件处理完成,则返回true

 

public boolean isChecked ()

         是否选中。

 

public void setCheckMarkDrawable (Drawable d)

为一个给定的Drawable设定检查标记。当isChecked()true时则绘制

参数

d      用于检查标记的Drawable

 

public void setCheckMarkDrawable (int resid)

为一个给定的Drawable设定检查标记,使用它的资源id来标识。当isChecked()true时则绘制

参数

resid  用于检查标记的Drawable

 

public void setChecked (boolean checked)

改变文本视图的选中状态

参数

checked 选中文本返回true,未选中返回false

 

public void setPadding (int left, int top, int right, int bottom)

设置页边距。视图可能会增加一些必要的空间用于显示滚动条,并依赖滚动条的类型和可见性。因此,设定的值用于回调getPaddingLeft(), getPaddingTop(), getPaddingRight() getPaddingBottom()时则返回不同的值

参数

left    左边距(使用“像素”单位)

top    上边距(使用“像素”单位)

right        右边距(使用“像素”单位)

bottom   下边距(使用“像素”单位)

 

public void toggle ()

反转当前视图的选中状态

 

补充

文章链接

      关于CheckedTextView的一些小东西

      Android API之CheckedTextView代码演示

      CheckedTextView 显示问题

 

示例代码

实现代码参加文章12,或者点这里下载。