在android2.2环境下,开发了一个自定义的button控件,继承自RadioButton
attrs.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MyRadioButton">
<attr name="value" format="string" />
</declare-styleable>
</resources>
MyRadioButton代码如下:
public class MyRadioButton extends RadioButton { public String value;
public String getValue() {
return value;
} public void setValue(String value) {
this.value = value;
} public MyRadioButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} public MyRadioButton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyRadioButton(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton);
this.value =a.getString(R.styleable.MyRadioButton_value);
a.recycle();
}
catch(Exception e)
{
e.printStackTrace();
}
}}
main.xml代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:eoe ="http://schemas.android.com/apk/res/cn.xuyi.button"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<cn.xuyi.button.MyRadioButton
eoe:value="true"
android:id="@+id/styleable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R.strings.mybuttontext"
>
</cn.xuyi.button.MyRadioButton>
</LinearLayout>
运行时产生错误:
error: No resource identifier found for attribute 'value' in package 'cn.xuyi.button'请高手帮忙看看,我已经搞了一天,在百度和谷歌都没查到解决方法。请高手不吝赐教
attrs.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MyRadioButton">
<attr name="value" format="string" />
</declare-styleable>
</resources>
MyRadioButton代码如下:
public class MyRadioButton extends RadioButton { public String value;
public String getValue() {
return value;
} public void setValue(String value) {
this.value = value;
} public MyRadioButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} public MyRadioButton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyRadioButton(Context context, AttributeSet attrs) {
super(context, attrs);
try
{
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton);
this.value =a.getString(R.styleable.MyRadioButton_value);
a.recycle();
}
catch(Exception e)
{
e.printStackTrace();
}
}}
main.xml代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:eoe ="http://schemas.android.com/apk/res/cn.xuyi.button"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<cn.xuyi.button.MyRadioButton
eoe:value="true"
android:id="@+id/styleable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R.strings.mybuttontext"
>
</cn.xuyi.button.MyRadioButton>
</LinearLayout>
运行时产生错误:
error: No resource identifier found for attribute 'value' in package 'cn.xuyi.button'请高手帮忙看看,我已经搞了一天,在百度和谷歌都没查到解决方法。请高手不吝赐教
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货