kanytu/android-parallax-recyclerview
View on GitHubIllegalStateException on adding parallax header
Open
#12 opened on Mar 6, 2015
help wanted
Description
Hi,
I was trying to implement parallax scrolling using this awesome library. But I ran into some problems. Am not sure I'm doing this right(first time android programmer). I'm getting this on adding parallaxheader.
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() >on the child's parent first.
I'll just give you a brief idea of what I did. I have a chart which is the header. So I extended your ParallaxRecyclerAdapter with a custom constructor, overrode some methods, and named it StatsAdapter
public StatsAdapter(LineChartData mChartData, final List<StatsItem> mListData) {
super(mListData);
this.mListData = mListData;
this.mChartData = mChartData;
implementRecyclerAdapterMethods(this);
}
And overrode setParallaxHeader like this
public void setParallaxHeader(View header, RecyclerView view) {
LineChartView chart = (LineChartView) header.findViewById(R.id.chart);
chart.setLineChartData(mChartData);
formatChart(chart);
super.setParallaxHeader(header, view);
}
And in the Fragment from which I'm loading the recyclerview, I did this
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.stats_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mStatsAdapter = new StatsAdapter(mChartData, mListData);
mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_chart_detail,mRecyclerView,false);
mStatsAdapter.setParallaxHeader(mHeaderView, mRecyclerView);
mRecyclerView.setAdapter(mStatsAdapter);
Any idea why I'm getting this error?