I'm having the following error while inflating a custom view component:
android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class .ScrollableRecyclerView
In line 68 inside TabFragment.java
View view = inflater.inflate(R.layout.tab_fragment, container, false);
Full log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.osupernerd.osupernerd, PID: 1048
android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class br.com.osupernerd.osn.components.ScrollableRecyclerView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at br.com.osupernerd.osn.fragments.TabFragment.onCreateView(TabFragment.java:68)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1643)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1272)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1120)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1646)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20214)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20214)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3083)
at android.view.View.measure(View.java:20214)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2683)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1636)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1928)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1524)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7520)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:622)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
ScrollableRecyclerView The class below is a custom RecyclerView, in the future it will implement some resources to control scroll parameters. For test purposes the init() method prints a log when it's ready.
This class will implement a custom view to "Pull to Refresh" and controller it inside RecyclerView.
public class ScrollableRecyclerView extends RecyclerView
{
private static final String TAG = "ScrollableRecyclerView";
private LayoutInflater inflater;
private RelativeLayout refreshView;
private TextView refreshViewText;
private ImageView refreshViewIcon;
private ProgressBar refreshViewProgress;
public ScrollableRecyclerView ( Context context )
{ super( context ); init( context ); }
public ScrollableRecyclerView ( Context context, AttributeSet attrs )
{ super( context, attrs ); init( context ); }
public ScrollableRecyclerView ( Context context, AttributeSet attrs, int defStyle )
{ super( context, attrs, defStyle ); init( context ); }
public void init ( Context context )
{
inflater = (LayoutInflater) context.getSystemService ( Context.LAYOUT_INFLATER_SERVICE );
refreshView = (RelativeLayout) inflater.inflate ( R.layout.refresh_header, this, false );
refreshViewText = (TextView) refreshView.findViewById ( R.id.refresh_text );
refreshViewIcon = (ImageView) refreshView.findViewById ( R.id.refresh_icon );
refreshViewProgress = (ProgressBar) refreshView.findViewById ( R.id.refresh_progress );
addView ( refreshView );
Log.d( TAG, "Ready...");
}
}
TabFragment Here, it's the Fragment that will have ScrollableRecyclerView custom component. It's important to say that nothing wrong is happening between MainActivity and TabFragment.
public class TabFragment extends Fragment implements IHTTPCallback
{
public final String TAG = "osn.TabFragment";
private ScrollableRecyclerView recyclerView;
public TabFragment ()
{}
@Override
public void onCreate( Bundle savedInstanceState )
{ super.onCreate(savedInstanceState); }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.tab_fragment, container, false);
this.recyclerView = (ScrollableRecyclerView) view.findViewById(R.id.posts_view);
this.recyclerView.setLayoutManager( new LinearLayoutManager( getContext() ) );
return view;
}
Here is tab_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<br.com.osupernerd.osn.components.ScrollableRecyclerView
android:id="@+id/posts_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="vertical">
</br.com.osupernerd.osn.components.ScrollableRecyclerView>
</RelativeLayout>
Here is refresh_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refresh_header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dp"
android:paddingBottom="15dp"
android:gravity="center"
>
<ProgressBar
android:id="@+id/refresh_progress"
android:indeterminate="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_marginRight="20dip"
android:layout_marginTop="10dip"
android:visibility="gone"
android:layout_centerVertical="true"
style="?android:attr/progressBarStyleSmall"
/>
<ImageView
android:id="@+id/refresh_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_marginRight="20dip"
android:visibility="gone"
android:layout_gravity="center"
android:gravity="center"
android:src="@drawable/ic_down"
/>
<TextView
android:id="@+id/refresh_text"
android:text="@string/refresh_tap_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:paddingTop="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
/>
</RelativeLayout>
OBSERVATIONS
When I use RecyclerView instead ScrollableRecyclerView... all works well!
When I remove the following code below, from ScrollableRecyclerView... all works well!
refreshView = (RelativeLayout) inflater.inflate ( R.layout.refresh_header, this, false );
refreshViewText = (TextView) refreshView.findViewById ( R.id.refresh_text );
refreshViewIcon = (ImageView) refreshView.findViewById ( R.id.refresh_icon );
refreshViewProgress = (ProgressBar) refreshView.findViewById ( R.id.refresh_progress );
addView ( refreshView );
Someone can help and say what's going wrong? If I can't inflate the component ScrollableRecyclerView, how can I dynamically insert a view inside its?