【发布时间】:2016-08-03 19:00:16
【问题描述】:
我已经制作了一个扩展线性布局的自定义数字选择器,我对构造函数有疑问,由于某种原因,当我将枚举传递给构造函数时,活动不会膨胀 XML。这是代码。
private TumblerSettings.TumblerTypes tumblerTypes;
public Tumbler(Context context, TumblerListener tumblerCallBack, TumblerSettings.TumblerTypes
tumblerTypes)
{
super(context);
this.mTumblerCallBack = tumblerCallBack;
this.tumblerTypes = tumblerTypes;
Log.i("sss", "Tumbler1: " + String.valueOf(tumblerTypes));
updateValue();
initControl(context);
//setCustomObjectListener(mTumblerCallBack);
}
public Tumbler(Context context, AttributeSet attrs, TumblerSettings.TumblerTypes
tumblerTypes)
{
super(context, attrs);
this.tumblerTypes = tumblerTypes;
Log.i("sss", "Tumbler2: " + String.valueOf(tumblerTypes));
updateValue();
initControl(context);
}
public Tumbler(Context context, AttributeSet attrs, int defStyle, TumblerSettings.TumblerTypes
tumblerTypes)
{
super(context, attrs, defStyle);
this.tumblerTypes = tumblerTypes;
Log.i("sss", "Tumbler3: " + String.valueOf(tumblerTypes));
updateValue();
initControl(context);
}
我用这段代码调用它
mTumbler = new Tumbler(MainActivity.this, new Tumbler.TumblerListener()
{
@Override
public void tumblerValue(final String value)
{
valueTextView.setText("value :" + value);
}
}, TumblerSettings.TumblerTypes.BRIGHTNESS);
我得到的错误是
E/AndroidRuntime: 致命异常: main java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.wheelsample/com.example.wheelsample.MainActivity}:android.view.InflateException:二进制 XML 文件第 26 行:膨胀类 com.example.wheelsample.tumblers 时出错。不倒翁 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 在 android.app.ActivityThread.access$600(ActivityThread.java:130) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
任何建议将不胜感激。谢谢
XML 代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.wheelsample.DualNumberPicker">
<LinearLayout
android:layout_width="75dp"
android:layout_height="120dp"
android:background="@drawable/assets_tmb_wide"
android:orientation="horizontal">
<com.example.wheelsample.TumblerNumberPicker
android:id="@+id/bpp"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"/>
</LinearLayout>
【问题讨论】:
标签: android android-layout android-custom-view