我已經擴展TextView
也執行Checkable
。我沒有碰過任何TextView
的東西,除了onCreateDrawableState
。此外,我剛剛實施了Checkable方法。 (有刪節的清晰度。)TextView擴展; UnsupportedOperationException
public class CheckableTextView extends TextView implements Checkable {
public CheckableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CheckedStateSet);
}
return drawableState;
}
它編譯於ICS罰款,但在Android 2.3的我得到一個非常奇怪的錯誤時,程序試圖誇大這一觀點。
10-31 00:51:20.414: E/AndroidRuntime(601): FATAL EXCEPTION: main
10-31 00:51:20.414: E/AndroidRuntime(601): android.view.InflateException: Binary XML file line #3: Error inflating class net.blackenvelope.utrechtafval.map.layouts.CheckableTextView
...
10-31 00:51:20.414: E/AndroidRuntime(601): Caused by: java.lang.reflect.InvocationTargetException
10-31 00:51:20.414: E/AndroidRuntime(601): at java.lang.reflect.Constructor.constructNative(Native Method)
10-31 00:51:20.414: E/AndroidRuntime(601): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
10-31 00:51:20.414: E/AndroidRuntime(601): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
10-31 00:51:20.414: E/AndroidRuntime(601): ... 45 more
10-31 00:51:20.414: E/AndroidRuntime(601): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
10-31 00:51:20.414: E/AndroidRuntime(601): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
10-31 00:51:20.414: E/AndroidRuntime(601): at android.view.View.<init>(View.java:1963)
10-31 00:51:20.414: E/AndroidRuntime(601): at android.widget.TextView.<init>(TextView.java:344)
10-31 00:51:20.414: E/AndroidRuntime(601): at android.widget.TextView.<init>(TextView.java:337)
10-31 00:51:20.414: E/AndroidRuntime(601): at net.app.layouts.CheckableTextView.<init>(CheckableTextView.java:11)
10-31 00:51:20.414: E/AndroidRuntime(601): ... 48 more
我似乎無法找出這種類型= 0X2手段。
這裏是XML:
<?xml version="1.0" encoding="utf-8"?>
<app.CheckableTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overlay_type_title"
android:layout_width="match_parent"
android:background="@drawable/overlay_list_bg_selector"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/overlay_list_icon"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="10dp"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
>
</app.CheckableTextView>
這意味着您將一個屬性作爲維值傳遞,可能在您的XML中。我們可以看到你正在膨脹的XML文件嗎? – Eric
啊,我真的沒有得到這個屬性業務。我想我從某個地方的某個例子中複製它。我將如何去硬編碼這些屬性?這是明智的嗎? – Maarten