-3

I'm using in my android app a RecycleView adapter to inflate a custom item layout for a contact list, but an error occurs if I run it. Can anyone help me?

My layout code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="4dp"
    app:cardPreventCornerOverlap="true"
    app:contentPadding="4dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp">

        <RelativeLayout
            android:id="@+id/topContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/avatar"
                style="@style/ContactListAvatarBlackTextStyle"
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_centerVertical="true"
                android:background="@drawable/contactlist_avatar_bg_black"
                android:gravity="center"
                android:text="E"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/lbl_contactName"
                style="@style/TextStyle51"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="28dp"
                android:layout_toRightOf="@+id/avatar"
                android:text="Bechir Segni" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/action_buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/topContainer"
            android:orientation="horizontal"
            android:weightSum="2">

            <Button
                android:id="@+id/btn_modify"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/app_name"
                android:theme="@style/ContactActionButtonTheme" />

            <Button
                android:id="@+id/btn_delete"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/app_name"
                android:theme="@style/ContactActionButtonTheme" />
        </LinearLayout>


    </RelativeLayout>
</android.support.v7.widget.CardView>

My style is:

<style name="ContactActionButtonTheme" parent="Widget.AppCompat.Button.Colored"> 
    <item name="android:textColor">@drawable/button_text_selector</item> 
    <item name="colorButtonNormal">@drawable/contact_action_button_bg</item> 
    <item name="colorControlHighlight">@color/colorHighlight</item> 
</style>

My logcat:

android.view.InflateException: Binary XML file line #53: Error inflating class Button
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    at tech.digitus.tayarapay.ui.contactlist.ContactListActivityAdapter.onCreateViewHolder(ContactListActivityAdapter.java:108)
    at tech.digitus.tayarapay.ui.contactlist.ContactListActivityAdapter.onCreateViewHolder(ContactListActivityAdapter.java:22)
    at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
  • 1
    Can you post your xml layout file which is used in adapter ? – Arti Patel Aug 14 '18 at 11:35
  • 1
    What is there in `XML file line #53` –  Aug 14 '18 at 11:35
  • 1
    Show your XML and update your question. I can help you – mducc Aug 14 '18 at 11:36
  • please add the code you are using – Abhinandan Aug 14 '18 at 11:40
  • i know what is error "Binary XML file line" u have a library on ur depency that not supp to ur version for example your library have supp android 4.4 to up but you are runing on Android version device <4.4 –  Aug 14 '18 at 11:42
  • the problem is accoured with the button theme, when i remove it , it work fine, but i'm need to styling the button??? My style is – ELHechmi Essalah Aug 14 '18 at 12:01
  • Seems like drawable not inflate properly. – Faysal Ahmed Aug 14 '18 at 12:09

3 Answers3

2

Try to avoid to use drawable for putting textColor.

<style name="ContactActionButtonTheme" parent="Widget.AppCompat.Button.Colored"> 
    <item name="android:textColor">@color/textColor</item> 
    <item name="colorButtonNormal">@color/colorButtonNormal</item> 
    <item name="colorControlHighlight">@color/colorHighlight</item> 
</style>

Provide the color that you want to use.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
0

Delete line:

android:layout_weight="1"
mducc
  • 743
  • 1
  • 9
  • 32
0

Thank for all, I find a solution, the problem is occurred by the drawable at "@drawable/contact_action_button_bg"

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <stroke android:width="1dp"
                android:color="@color/colorPrimary" />
            <solid android:color="@color/colorPrimary"></solid>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <stroke android:width="1dp"
                android:color="@color/colorPrimary" />
            <solid android:color="@color/colorPrimary"></solid>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <stroke android:width="1dp"
                android:color="@color/colorPrimary" />
            <solid android:color="@color/white"></solid>
        </shape>
    </item>
</selector>

I replaced it by this one

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/colorButtonActived" android:state_activated="true" />
    <item android:color="@color/white" android:state_enabled="false" />
    <item android:color="@color/white" android:state_active="false" />
    <item android:color="@color/white" />
</selector>