Android开发自定义组合控件

来源:互联网 发布:淘宝租房在哪个地方 编辑:程序博客网 时间:2024/06/03 13:32
public class MyRegItemView extends RelativeLayout{    private TextView leftTextView;    private TextView rightTextView;    private ImageView rightImageView;    public MyRegItemView(Context context, @Nullable AttributeSet attrs) {        super(context, attrs);        LayoutInflater.from(context).inflate(R.layout.item_reg_baseinfo, this, true);        leftTextView = (TextView)findViewById(R.id.tv_left_msg);        rightTextView = (TextView)findViewById(R.id.tv_right_msg);        rightImageView = (ImageView)findViewById(R.id.iv_right);        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.MyRegItemView);        if(attributes != null){            String leftMsg = attributes.getString(R.styleable.MyRegItemView_leftMsg);            String rightMsg = attributes.getString(R.styleable.MyRegItemView_rightMsg);            int rightImageSrc = attributes.getResourceId(R.styleable.MyRegItemView_rightImageSrc,R.mipmap.ic_right);            rightImageView.setImageResource(rightImageSrc);            if(!TextUtils.isEmpty(leftMsg)){                leftTextView.setText(leftMsg);            }            if(!TextUtils.isEmpty(rightMsg)){                rightTextView.setText(rightMsg);            }            attributes.recycle();        }    }    public void setRightResult(String result){        if(!TextUtils.isEmpty(result)){            rightTextView.setText(result);        }    }}

原创粉丝点击