endian11
2020-12-01 f1e0868392f26cea1ccd45ec78d759d5205e5dc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package safeluck.drive.evaluation.fragment.rulefragments.cview;
 
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;
 
import safeluck.drive.evaluation.R;
 
/**
 * DriveJudge
 * Created by lzw on 2020/9/24. 10:25:00
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
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);
    }
 
    public TextCheckBox(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }
 
    public TextCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }
 
    public TextCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context,attrs);
    }
 
    private void initView(Context context, AttributeSet attrs) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_text_checkbox,this,true);
        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;
    }
}