I have some problem on Implementation of fragments with TabLayout. I have 3 tabs and I hardcoded some values and googlemaps(v2). When I run program it's showing three tabs with all the harcoded values and googlemaps(v2). when I swipe from first time and second time it's working fine. But when I swipe third time It's showing Layout Inflate error. Please Help me..
Here I am attaching full code with stack Trace.
This is My First Fragment.
public class RequestedBookingsFragment extends Fragment {
SharedPreferences prefs;
SharedPreferences.Editor editor_prefs;
TextView tv;
GoogleMap map;
RecyclerView rb_recycler_view;
List<PojoFromToLatLng> pojoFromToLatLngs;
LinearLayoutManager llm;
public RequestedBookingsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_requested_bookings, container, false);
tv = (TextView) rootView.findViewById(R.id.tv_id);
rb_recycler_view = (RecyclerView) rootView.findViewById(R.id.recyler_rb);
llm = new LinearLayoutManager(getActivity());
rb_recycler_view.setLayoutManager(llm);
rb_recycler_view.setHasFixedSize(true);
intializeData();
initializeAdapter();
return rootView;
}
private void intializeData() {
pojoFromToLatLngs = new ArrayList<>();
pojoFromToLatLngs.add(new PojoFromToLatLng("JayaMahal Office", "Koramangala", "22:22:22", "Accepted"));
}
private void initializeAdapter() {
RecyclerCardMapAdapter adapter = new RecyclerCardMapAdapter(pojoFromToLatLngs);
rb_recycler_view.setAdapter(adapter);
}
Adapter for FirstFragment:
public class RecyclerCardMapAdapter extends RecyclerView.Adapter<RecyclerCardMapAdapter.MapBookingsHolder> {
GoogleMap mMap;
public class MapBookingsHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
CardView main_card, sub_card;
TextView from_address_text,to_address_text, time_tv, booking_status_tv;
Button accept_booking_btn;
public MapBookingsHolder(View itemView) {
super(itemView);
from_address_text = (TextView) itemView.findViewById(R.id.from_rb);
to_address_text = (TextView) itemView.findViewById(R.id.to_rb);
time_tv = (TextView) itemView.findViewById(R.id.time_id_rb);
booking_status_tv = (TextView) itemView.findViewById(R.id.booking_status_id_rb);
accept_booking_btn = (Button) itemView.findViewById(R.id.bookings_accept_button_rb);
}
@Override
public void onClick(View v) {
}
}
List<PojoFromToLatLng> pojoFromToLatLngs;
RecyclerCardMapAdapter(List<PojoFromToLatLng> pojoFromToLatLngs1)
{
this.pojoFromToLatLngs=pojoFromToLatLngs1;
}
@Override
public RecyclerCardMapAdapter.MapBookingsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.requested_bookings_card_map, parent,false);
MapBookingsHolder mbh=new MapBookingsHolder(v);
return mbh;
}
@Override
public void onBindViewHolder(RecyclerCardMapAdapter.MapBookingsHolder holder, int position) {
}
@Override
public int getItemCount() {
return pojoFromToLatLngs.size();
}
}
XML for FirstFragment:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cabbi.appstract.RequestedBookingsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Requested Bookings"
android:id="@+id/tv_id"
android:textSize="20dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyler_rb">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
This is my Second Fragment.
public class AcceptedBookingsFragment extends Fragment {
RecyclerView ab_recycler_view;
List<PojoFromToLatLng> pojoFromToLatLngs;
LinearLayoutManager llm;
public AcceptedBookingsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_accepted_bookings, container, false);
ab_recycler_view = (RecyclerView) rootView.findViewById(R.id.recyler_ab);
llm = new LinearLayoutManager(getActivity());
ab_recycler_view.setLayoutManager(llm);
ab_recycler_view.setHasFixedSize(true);
intializeData();
initializeAdapter();
return rootView;
}
private void intializeData() {
pojoFromToLatLngs = new ArrayList<>();
pojoFromToLatLngs.add(new PojoFromToLatLng("JayaMahal Office", "Koramangala", "22:22:22", "Accepted"));
}
private void initializeAdapter() {
AcceptingBookingAdapter adapter = new AcceptingBookingAdapter(pojoFromToLatLngs);
// places_type_list_recyclerView.addItemDecoration(new SimpleDividerItemDecoration(this));
ab_recycler_view.setAdapter(adapter);
}
}
Adapter For Second Fragment:
public class AcceptingBookingAdapter extends RecyclerView.Adapter<AcceptingBookingAdapter.MapBookingsHolder> {
GoogleMap mMap;
public class MapBookingsHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
CardView main_card, sub_card;
TextView from_address_text,to_address_text, time_tv, booking_status_tv;
Button accept_booking_btn;
public MapBookingsHolder(View itemView) {
super(itemView);
from_address_text = (TextView) itemView.findViewById(R.id.from_ab);
to_address_text = (TextView) itemView.findViewById(R.id.to_ab);
time_tv = (TextView) itemView.findViewById(R.id.time_id_ab);
booking_status_tv = (TextView) itemView.findViewById(R.id.booking_status_id_ab);
accept_booking_btn = (Button) itemView.findViewById(R.id.bookings_accepted_button_ab);
}
@Override
public void onClick(View v) {
}
// @Override
// public void onMapReady(GoogleMap googleMap) {
// mMap = googleMap;
//
// }
}
List<PojoFromToLatLng> pojoFromToLatLngs;
AcceptingBookingAdapter(List<PojoFromToLatLng> pojoFromToLatLngs1)
{
this.pojoFromToLatLngs=pojoFromToLatLngs1;
}
@Override
public AcceptingBookingAdapter.MapBookingsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.accetpted_booking_cards_map, parent,false);
MapBookingsHolder mbh=new MapBookingsHolder(v);
return mbh;
}
@Override
public void onBindViewHolder(AcceptingBookingAdapter.MapBookingsHolder holder, int position) {
}
@Override
public int getItemCount() {
return pojoFromToLatLngs.size();
}
}
XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cabbi.appstract.AcceptedBookingsFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accpeted Bookings"
android:id="@+id/tv_id1"
android:textSize="20dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyler_ab">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
Third Fragment:
public class AllBookingsFragment extends Fragment {
TextView tv;
RecyclerView allb_recycler_view;
List<PojoFromToLatLng> pojoFromToLatLngs;
LinearLayoutManager llm;
public AllBookingsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_all_bookings, container, false);
allb_recycler_view = (RecyclerView) rootView.findViewById(R.id.recyler_allb);
llm = new LinearLayoutManager(getActivity());
allb_recycler_view.setLayoutManager(llm);
allb_recycler_view.setHasFixedSize(true);
intializeData();
initializeAdapter();
return rootView;
}
private void intializeData() {
pojoFromToLatLngs = new ArrayList<>();
pojoFromToLatLngs.add(new PojoFromToLatLng("JayaMahal Office", "Koramangala", "22:22:22", "Accepted"));
}
private void initializeAdapter() {
AllBookingsAdapter adapter = new AllBookingsAdapter(pojoFromToLatLngs);
// places_type_list_recyclerView.addItemDecoration(new SimpleDividerItemDecoration(this));
allb_recycler_view.setAdapter(adapter);
}
}
Adapter For Third Fragment:
public class AllBookingsAdapter extends RecyclerView.Adapter<AllBookingsAdapter.MapBookingsHolder> {
GoogleMap mMap;
public class MapBookingsHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
CardView main_card, sub_card;
TextView from_address_text,to_address_text, time_tv, booking_status_tv;
//Button accept_booking_btn;
public MapBookingsHolder(View itemView) {
super(itemView);
from_address_text = (TextView) itemView.findViewById(R.id.from_allb);
to_address_text = (TextView) itemView.findViewById(R.id.to_allb);
time_tv = (TextView) itemView.findViewById(R.id.time_id_allb);
booking_status_tv = (TextView) itemView.findViewById(R.id.booking_status_id_allb);
//accept_booking_btn = (Button) itemView.findViewById(R.id.bookings_accept_button_allb);
}
@Override
public void onClick(View v) {
}
// @Override
// public void onMapReady(GoogleMap googleMap) {
// mMap = googleMap;
//
// }
}
List<PojoFromToLatLng> pojoFromToLatLngs;
AllBookingsAdapter(List<PojoFromToLatLng> pojoFromToLatLngs1)
{
this.pojoFromToLatLngs=pojoFromToLatLngs1;
}
@Override
public AllBookingsAdapter.MapBookingsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.all_bookings_card_map, parent,false);
MapBookingsHolder mbh=new MapBookingsHolder(v);
return mbh;
}
@Override
public void onBindViewHolder(AllBookingsAdapter.MapBookingsHolder holder, int position) {
}
@Override
public int getItemCount() {
return pojoFromToLatLngs.size();
}
}
XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cabbi.appstract.AllBookingsFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Bookings"
android:id="@+id/tv_id2"
android:textSize="20dp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyler_allb">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
I am inflating the below layout in all the fragments by using the AdapterClass Which I have mentioned above.
Inflating Layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="350dp"
android:id="@+id/cardview_map_rb"
android:background="@color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/maps_inside_card_rb"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="147dp"
android:id="@+id/sub_card_for_locs_rb">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/from_rb"
android:text="JAYAMAHAL"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/to_rb"
android:text="EJIPURA"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time_id_rb"
android:textSize="19dp"
android:text="23:55:22 15-06-2016"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/booking_status_id_rb"
android:text="Pending"
android:textSize="19dp"
android:layout_marginLeft="60dp"/>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bookings_accept_button_rb"
android:text="Accept"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I created three layouts with same data but different Id's (example: for Adapter1->layout1 , for Adapter2->layout2). But here I am pasting code for one layout because all have same vaules.
I have been working on these from yesterday.. I have googled answer I have SO answers but Not able to get Solution.
Here is my Error trace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cabbi.appstract, PID: 5522
android.view.InflateException: Binary XML file line #18: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.cabbi.appstract.RecyclerCardMapAdapter.onCreateViewHolder(RecyclerCardMapAdapter.java:57)
at com.cabbi.appstract.RecyclerCardMapAdapter.onCreateViewHolder(RecyclerCardMapAdapter.java:20)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at android.view.View.measure(View.java:17915)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1560)
at android.view.View.measure(View.java:17915)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:846)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:512)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1192)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:733)
at android.view.View.measure(View.java:17915)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)
at android.view.View.measure(View.java:17915)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)
at android.widget.L
Please help me.. Thanks in advance..............