Robert Golusiński
Robert Golusiński

Reputation: 358

Error inflating class Seekbar

I'm trying to inflate a custom view into alert dialog.

here is the code that creates the dialog and inflates the view:

        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();

here is the exception:

Unhandled Exception:

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class Seekbar

here is the 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>

The exception is thrown only when the volume_seekbar_layout has Seekbar element in it. When i try to inflate it for example with a TextView inside, it works properely.

Upvotes: 0

Views: 879

Answers (1)

Cheesebaron
Cheesebaron

Reputation: 24460

You have a typo in SeekBar. SeekBar uses UpperCamel casing of the two words Seek and Bar:

<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>

Upvotes: 1

Related Questions