错误导致类Seekbar

时间:2017-02-06 14:30:35

标签: xml xamarin xamarin.android layout-inflater android-seekbar

我正在尝试将自定义视图扩展为警告对话框。

这是创建对话框并使视图膨胀的代码:

        SeekBar volume = new SeekBar(this);
        volume = FindViewById<SeekBar>(Resource.Id.seekbar_volume);
        LayoutInflater inflater = (LayoutInflater)GetSystemService(LayoutInflaterService);

        Exception at this line --> AlertDialog.Builder volumeDialog = new AlertDialog.Builder(this)
            .SetTitle("How much milk the baby drank?")
            .SetView(inflater.Inflate(Resource.Layout.volume_seekbar_layout, null))
            .SetCancelable(false);

        volumeDialog.SetPositiveButton("OK", (senderAlert, args) => // OK button click
       {
           Toast.MakeText(this, volume.Progress.ToString(), ToastLength.Short).Show();
       }).Create().Show();

这是例外:

  

未处理的例外:

     

Android.Views.InflateException:二进制XML文件行#1:二进制XML   文件行#1:错误膨胀类Seekbar

这是volume_seekbar_layout.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/volume_seekbar_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

  <Seekbar android:id="@+id/seekbar_volume"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
  </Seekbar>

</RelativeLayout>

的AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="FeedingTime.FeedingTime" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
    <uses-sdk />
    <application android:icon="@drawable/Icon" android:label="Feeding Time" android:theme="@style/AppTheme">
    </application>
</manifest>

仅当volume_seekbar_layout中包含Seekbar元素时才会抛出异常。当我试图用文本内部的TextView来充气时,它会正常工作。

1 个答案:

答案 0 :(得分:1)

SeekBar中有拼写错误。 SeekBar使用了Seek和Bar这两个词的UpperCamel大小写:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/volume_seekbar_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

  <SeekBar android:id="@+id/seekbar_volume"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
  </SeekBar>

</RelativeLayout>