packagecom.qingguow.mobilesafe.ui;importandroid.content.Context;importandroid.util.AttributeSet;importandroid.view.View;importandroid.widget.CheckBox;importandroid.widget.RelativeLayout;importandroid.widget.TextView;importcom.qingguow.mobilesafe.R;public class SettingItemView extendsRelativeLayout {privateTextView tv_title;privateTextView tv_desc;privateCheckBox cb_status;privateString desc_on;privateString desc_off;/*** 初始化View对象
*@paramcontext*/
private voidinitView(Context context) {
View.inflate(context, R.layout.setting_item_view,this);
cb_status=(CheckBox) this.findViewById(R.id.cb_status);
tv_desc=(TextView) this.findViewById(R.id.tv_desc);
tv_title=(TextView) this.findViewById(R.id.tv_title);
}/*** 判断是否选中
*@return
*/
public booleanisChecked(){returncb_status.isChecked();
}/*** 设置是否选中
*@paramstatus*/
public void setChecked(booleanstatus){if(status){
tv_desc.setText(desc_on);
}else{
tv_desc.setText(desc_off);
}
cb_status.setChecked(status);
}/*** 设置显示文本
*@paramtext*/
public voidsetDesc(String text){
tv_desc.setText(text);
}public SettingItemView(Context context, AttributeSet attrs, intdefStyle) {super(context, attrs, defStyle);
initView(context);
}publicSettingItemView(Context context, AttributeSet attrs) {super(context, attrs);
initView(context);
//获取传递的属性
String title=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "title");
tv_title.setText(title);
desc_on=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "desc_on");
desc_off=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "desc_off");
}publicSettingItemView(Context context) {super(context);
initView(context);
}
}