2016-06-16 15 views
0

Ich habe ein Problem bei der Implementierung von Fragmenten mit TabLayout. Ich habe 3 Tabs und habe einige Werte und googlemaps festgeschrieben (v2). Wenn ich das Programm starte, werden drei Registerkarten mit allen harcodierten Werten und googlemaps (v2) angezeigt. wenn ich vom ersten Mal zum zweiten Mal wische, funktioniert es gut. Aber wenn ich das dritte Mal wische, wird der Layout-Aufblasen-Fehler angezeigt. Bitte helfen Sie mir ..Fehler in TabLayout Fragment

Hier füge ich vollständigen Code mit Stack-Trace.

Dies ist mein erstes 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 für 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 für 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> 

Dies ist mein zweites 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 für zweites 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> 

Dritter Teil:

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 für die dritte 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> 

Ich bin das unten stehende Layout in allen Fragmenten Aufpumpen durch den AdapterClass verwendet, die ich oben erwähnt habe.

Inflating Das Layout ist:

<?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> 

Ich habe drei Layouts mit gleichen Daten, aber unterschiedliche IDs (Beispiel: Adapter1-> Layout1, für Adapter2-> Layout2). Aber hier paste ich Code für ein Layout, weil alle gleiche vaules haben.

Ich habe an diesen von gestern gearbeitet .. Ich habe gegoogelt Antwort Ich habe SO Antworten, aber nicht in der Lage, Lösung zu bekommen.

Hier ist mein Fehler-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 

Bitte helfen Sie mir .. Vielen Dank im Voraus ..............

+0

geben Sie bitte den Code, den Sie arbeiten und möglicherweise die Fehlermeldung. –

+0

Da beim zweiten Streichen kein Fehler auftritt, werden die Tabs korrekt erstellt (beim zweiten Streichen wird auch das dritte Tab erstellt). Ein Grund wäre die falsche Anzahl von Tabs. Mein Vorschlag: In android studio ein neues Projekt erstellen und "Tabbed Activity hinzufügen". Passen Sie es dann an Ihr Projekt an. Wenn Sie mehr Details bekommen, könnte ich vielleicht besser helfen. – Behy

+0

@Behy Danke für schnelle Antwort .. Ich habe meinen vollständigen Code hier eingefügt .. Bitte sagen Sie mir, wo ich Fehler mache –

Antwort