MvvmCross / MvvmCross-AndroidSupport

Android support library packages for MvvmCross: The .NET MVVM framework for cross-platform solutions.
http://mvvmcross.com
15 stars 0 forks source link

Error to inflate a dialog with MvxExpandableListView #320

Closed viniciusmaia closed 7 years ago

viniciusmaia commented 7 years ago

I'm trying to inflate a dialog with MvxExpandbaleListView and the app crashes with a ClassNotFoundException. The exception message is: "Didn't find class "android.view.MvxExpandableListView".

Here is my dialog axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/margemVertical"
    android:paddingBottom="@dimen/margemVertical">
    <android.support.v7.widget.AppCompatImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:scaleType="center"
        android:padding="10dp"
        android:tint="@android:color/white"
        local:srcCompat="@drawable/ic_lista" />
    <TextView
        android:id="@+id/txtTitulo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:gravity="center"
        android:textSize="18sp"
        android:textStyle="bold"
        android:textAllCaps="true"
        android:textColor="@color/colorPrimary" />
    <SearchView
        android:layout_marginLeft="@dimen/margemHorizontal"
        android:layout_marginRight="@dimen/margemHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="2dp"
        android:background="#fff"
        android:iconifiedByDefault="false"
        android:id="@+id/searchView"
        android:queryHint="@string/textPesquisar" />
    <android.support.design.widget.TextInputLayout
        android:id="@+id/txtInptFiltroAgrupador"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margemVertical"
        local:hintTextAppearance="@style/labelSize">
        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/editFiltroAgrupador"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionNext"
            android:hint="Agrupar Por"
            android:textSize="@dimen/tamanhoFonteTextoSecundario"
            android:focusable="false" />
    </android.support.design.widget.TextInputLayout>
    <MvxExpandableListView
        android:groupIndicator="@null"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margemVertical"
        android:layout_marginLeft="@dimen/list_margemHorizontal"
        android:layout_marginRight="@dimen/list_margemHorizontal"
        android:id="@+id/expandableList"
        android:footerDividersEnabled="true"
        android:headerDividersEnabled="true"
        android:dividerHeight="1dp"
        android:textFilterEnabled="false"
        android:layout_weight="1"
        android:clickable="true"
        local:MvxGroupItemTemplate="@layout/listaagrupadagroupitem"
        local:MvxItemTemplate="@layout/listitem" />
    <Button
        android:id="@+id/botaoCancelar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginTop="@dimen/margemVertical"
        android:layout_marginBottom="@dimen/margemVertical"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/branco"
        android:text="@string/textCancelar"
        android:backgroundTint="@color/colorPrimary" />
</LinearLayout>

Here is the code that I'm using to inflate the dialog:

var alertDialogBuilder = new AlertDialog.Builder(Activity);

            var viewListaDialog = Activity.LayoutInflater.Inflate(Resource.Layout.ListaAgrupadaDialog, null);
            var botaoCancelar = viewListaDialog.FindViewById<Button>(Resource.Id.botaoCancelar);
            var expandableListView = viewListaDialog.FindViewById<MvxExpandableListView>(Resource.Id.expandableList);
            var expandableListAdapter = new ListaAgrupadaSelecaoAdapter(Activity, BindingContext as IMvxAndroidBindingContext);
            expandableListView.SetAdapter(expandableListAdapter);

            alertDialogBuilder.SetView(viewListaDialog);
            var dialog = alertDialogBuilder.Show();

The error occurs when the line "Activity.LayoutInflater.Inflate(Resource.Layout.ListaAgrupadaDialog, null);" is executed.

I'm trying to do this inside of a MvxFragment (Support V4)

Cheesebaron commented 7 years ago

You are not using BindingInflate. Androids default inflater does not know about our abbreviations.

Also, next time, please use the Issue template.

viniciusmaia commented 7 years ago

that's worked. Thanks!