| | |
| | | import android.content.Context; |
| | | import android.content.res.TypedArray; |
| | | import android.util.AttributeSet; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.widget.CheckBox; |
| | | import android.widget.CompoundButton; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class TextCheckBox extends LinearLayout { |
| | | public class TextCheckBox extends LinearLayout implements View.OnClickListener { |
| | | |
| | | private CheckBox checkBox; |
| | | private boolean isChecked = false; |
| | | private static final String TAG = "TextCheckBox"; |
| | | public TextCheckBox(Context context) { |
| | | this(context,null); |
| | | } |
| | |
| | | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextCheckBox_attr_tvcheck); |
| | | String string = typedArray.getString(R.styleable.TextCheckBox_attr_tvcheck_txt_des_check); |
| | | boolean aBoolean = typedArray.getBoolean(R.styleable.TextCheckBox_attr_tvcheck_check_not, false); |
| | | |
| | | isChecked = aBoolean; |
| | | TextView text = view.findViewById(R.id.tv_checkbox); |
| | | text.setText(string); |
| | | checkBox = view.findViewById(R.id.check_setting); |
| | | |
| | | checkBox.setChecked(aBoolean); |
| | | checkBox.setClickable(false); |
| | | checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| | | @Override |
| | | public void onCheckedChanged(CompoundButton buttonView, boolean Checked) { |
| | | Log.i(TAG,"点击了checkbox checked="+Checked); |
| | | isChecked = Checked; |
| | | } |
| | | }); |
| | | |
| | | setOnClickListener(this); |
| | | } |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | Log.i(TAG,"点击,未取反之前isChecked="+isChecked); |
| | | isChecked =!isChecked; |
| | | checkBox.setChecked(isChecked); |
| | | } |
| | | |
| | | /** |
| | | * 获取Checkbox是否选中状态,选中为true |
| | | * |
| | | * @return |
| | | */ |
| | | public boolean isChecked(){ |
| | | return isChecked; |
| | | } |
| | | } |