2013-11-19 2 views
1

Этот вид был задан вопрос раньше, но я до сих пор не могу получить повесить его так, спрашиваю я снова так или иначеДобавление фрагмента на андроид TabFragment причин повесить

я получил повесить в течение нескольких секунд (хорошо не только несколько, это около 10 секунд) при попытке добавить новый фрагмент вкладки в мою активность, которая служит хостом для всех остальных фрагментов. Я добавил несколько фрагментов, не сталкиваясь с какой-либо проблемой, и есть один фрагмент, который дает мне упомянутую проблему.

Каждый раз, когда я создаю новую вкладку и добавления этого фрагмента трассировки стека производит этот следующий результат,

11-19 20:54:30.403: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.403: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.403: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.403: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.411: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.419: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.419: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.419: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.419: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
11-19 20:54:30.419: E/Dynamiclayout(13299): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 

Это макет фрагмента, который я хотел бы добавить:

<RelativeLayout 
       android:id="@+id/description" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_toRightOf="@+id/menu" 
       android:background="#FFFFFF" > 
      <ScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:fillViewport="true" 
       > 
      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_marginBottom="30dp"> 
       <LinearLayout 
        android:id="@+id/simulate_desc" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" > 

        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" > 
         <RelativeLayout 
          android:id="@+id/active_task" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:paddingLeft="@dimen/padding_description" 
          android:layout_marginTop="30dp" > 
          <TextView 
           android:id="@+id/desc_title" 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           android:text="Location Incident" 
           android:textScaleX="0.8" 
           android:textSize="@dimen/desc_title" 
           android:textColor="#f47a5c" 
           android:textStyle="bold" /> 
         </RelativeLayout> 

         <ImageView 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/active_task" 
          android:src="@drawable/stroke" 
          android:layout_marginRight="20dp" 
          android:layout_marginLeft="5dp" 
          /> 

         <RelativeLayout 
          android:id="@+id/Address" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_below="@+id/active_task" 
          android:padding="@dimen/padding_description" > 

          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_marginRight="10dp" 
           android:layout_height="wrap_content" > 

           <TextView 
            android:id="@+id/address_incident_label" 
            android:text="Address :" 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 
           <EditText 
            android:layout_marginTop="5dp" 
            android:id="@+id/address_incident" 
            android:hint="address" 
            android:paddingLeft="10dp" 
            android:layout_height="40dp" 
            android:layout_width="fill_parent" 
            android:layout_below="@+id/address_incident_label" 
            /> 


          </RelativeLayout> 
         </RelativeLayout> 



         <RelativeLayout 
          android:id="@+id/Incident" 
          android:layout_below="@+id/Address" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginRight="10dp" 
          android:padding="@dimen/padding_description" 
          > 
          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" > 

           <TextView 
            android:id="@+id/incident_report" 
            android:text="Incident Report " 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 

           <TextView 
            android:id="@+id/incident_report2" 
            android:text="Input the details of data from incident" 
            android:textSize="12sp" 
            android:textScaleX="0.8" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:layout_below="@+id/incident_report" 
            android:layout_marginLeft="2dp" 
            /> 
           <!-- incident detail --> 
           <LinearLayout 
            android:layout_marginTop="20dp" 
            android:layout_below="@+id/incident_report2" 
            android:id="@+id/incident_linear_detail1" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:layout_marginRight="20dp" 
            android:orientation="horizontal" 
            > 
            <TextView 
             android:layout_marginLeft="20dp" 
             android:text="Date" 
             android:textScaleX="0.8" 
             android:layout_height="wrap_content" 
             android:layout_width="wrap_content" 
             android:textSize="20sp" 
             android:layout_marginRight="48dp" 
             android:textColor="#000" 
             /> 

            <EditText 
             android:id="@+id/incident_date" 
             android:layout_height="40dp" 
             android:layout_width="40dp" 
             android:singleLine="true" 
             /> 
            <EditText 
             android:id="@+id/incident_month" 
             android:layout_width="40dp" 
             android:layout_height="40dp" 
             android:singleLine="true" 
             /> 
            <EditText 
             android:id="@+id/incident_year" 
             android:layout_width="80dp" 
             android:layout_height="40dp" 
             android:singleLine="true" 
             /> 
            <TextView 
             android:id="@+id/label_time" 
             android:layout_height="wrap_content" 
             android:layout_width="wrap_content" 
             android:textSize="20sp" 
             android:scaleX="0.7" 
             android:text="Time" 
             /> 
            <EditText 
             android:id="@+id/incident_time" 
             android:layout_height="40dp" 
             android:layout_width="fill_parent" 
             android:singleLine="true" 
             android:editable="false" 
             /> 

           </LinearLayout> 

           <!-- 2 --> 
           <LinearLayout 
            android:layout_marginTop="5dp" 
            android:layout_below="@+id/incident_linear_detail1" 
            android:id="@+id/incident_linear_detail2" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:layout_marginRight="20dp" 
            android:orientation="horizontal" 
            > 

            <TextView 
             android:layout_marginLeft="20dp" 
             android:text="Location" 
             android:textScaleX="0.8" 
             android:layout_height="wrap_content" 
             android:layout_width="wrap_content" 
             android:textSize="20sp" 
             android:layout_marginRight="20dp" 
             android:textColor="#000" 
             /> 
            <EditText 
             android:id="@+id/incident_location" 
             android:layout_height="40dp" 
             android:layout_width="fill_parent" 
             android:hint="Incident Location" 
             android:paddingLeft="10dp" 
             android:singleLine="true" 
             /> 

           </LinearLayout> 

           <!-- 3 --> 

           <LinearLayout 
            android:layout_marginTop="5dp" 
            android:layout_below="@+id/incident_linear_detail2" 
            android:id="@+id/incident_linear_detail3" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:layout_marginRight="20dp" 
            android:orientation="horizontal" 
            > 

            <TextView 
             android:layout_marginLeft="20dp" 
             android:text="Speed" 
             android:textScaleX="0.8" 
             android:layout_height="wrap_content" 
             android:layout_width="wrap_content" 
             android:textSize="20sp" 
             android:layout_marginRight="20dp" 
             android:textColor="#000" 
             /> 
            <EditText 
             android:id="@+id/incident_speed" 
             android:layout_height="40dp" 
             android:layout_width="fill_parent" 
             android:layout_marginLeft="17dp" 
             android:hint="Speed of your car" 
             android:singleLine="true" 
             /> 

           </LinearLayout> 





          </RelativeLayout> 
         </RelativeLayout> 


         <RelativeLayout 
          android:id="@+id/Describe" 
          android:layout_below="@+id/Incident" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:padding="@dimen/padding_description" > 
          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginRight="20dp" 
           > 

           <TextView 
            android:id="@+id/incident_description_label" 
            android:text="Describe the Incident" 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 
           <EditText 
            android:layout_below="@+id/incident_description_label" 
            android:id="@+id/incident_description" 
            android:layout_height="40dp" 
            android:layout_width="fill_parent" 
            android:hint="Description" 
            /> 


          </RelativeLayout>  
         </RelativeLayout> 



         <RelativeLayout 
          android:id="@+id/Upload" 
          android:layout_below="@+id/Describe" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          > 
          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginRight="20dp" 
           android:paddingLeft="10dp" 
           > 

           <TextView 

            android:id="@+id/upload_car_label" 
            android:text="Upload Car Picture" 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginTop="5dp" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 

           <TextView 
            android:layout_below="@+id/upload_car_label" 
            android:id="@+id/upload_car_label2" 
            android:text="Input the details of data from incident" 
            android:textSize="12sp" 
            android:textScaleX="0.8" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:layout_marginLeft="2dp" 

            /> 

           <ImageView 
            android:id="@+id/incident_photo_car" 
            android:layout_height="80dp" 
            android:layout_width="80dp" 
            android:src="@drawable/upload" 
            android:layout_alignParentRight="true" 
            /> 

          </RelativeLayout>  
         </RelativeLayout> 


         <RelativeLayout 
          android:id="@+id/Foto" 
          android:layout_below="@+id/Upload" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          > 
          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginRight="20dp" 
           android:paddingLeft="10dp" 
           > 

           <TextView 
            android:id="@+id/license_label" 
            android:text="License Photo" 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 

           <TextView 
            android:layout_below="@+id/license_label" 
            android:id="@+id/license_label2" 
            android:text="Input the details of data from incident" 
            android:textSize="12sp" 
            android:textScaleX="0.8" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:layout_marginLeft="2dp" 
            /> 

           <ImageView 
            android:id="@+id/incident_photo_license" 
            android:layout_height="80dp" 
            android:layout_width="80dp" 
            android:src="@drawable/upload" 
            android:layout_alignParentRight="true" 
            /> 


          </RelativeLayout>  
         </RelativeLayout> 


         <RelativeLayout 
          android:id="@+id/Tampak" 
          android:layout_below="@+id/Foto" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          > 
          <RelativeLayout 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginRight="20dp" 
           android:paddingLeft="10dp" 
           > 

           <TextView 
            android:id="@+id/tampak_label" 
            android:text="Front/Back View" 
            android:textSize="@dimen/desc_title" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textScaleX="0.7" 
            android:layout_marginLeft="2dp" 
            android:textColor="#000" 
            /> 

           <TextView 
            android:layout_below="@+id/tampak_label" 
            android:id="@+id/tampak_label2" 
            android:text="Foto yang diambil dari tampak depan dan belakang" 
            android:textSize="12sp" 
            android:textScaleX="0.8" 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:layout_marginLeft="2dp" 
            /> 

           <ImageView 
            android:id="@+id/incident_photo_frontback" 
            android:layout_height="80dp" 
            android:layout_width="80dp" 
            android:src="@drawable/upload" 
            android:layout_alignParentRight="true" 
            /> 


          </RelativeLayout>  
         </RelativeLayout> 

        </RelativeLayout> 
       </LinearLayout> 

       <Button 
        android:id="@+id/btn_next_claim" 
        android:layout_alignParentRight="true" 
        android:layout_below="@+id/simulate_desc" 
        android:layout_width="180dp" 
        android:layout_height="50dp" 
        android:text="next" 
        android:background="@drawable/btn_red" 
        android:textSize="@dimen/text_profile_size" 
        android:textColor="#FFFFFF" 
        android:layout_marginTop="20dp" 
        android:layout_marginRight="10dp" 
        android:onClick="nextClaim" 
        /> 


       </RelativeLayout> 
       </ScrollView> 
      </RelativeLayout> 

Фрагмент не выполняет выполнить задачу. Я просто просто надуть его на моем onCreateView метод по классу фрагмента. Но, как вы видите, он содержит тяжелый пользовательский интерфейс (имеет так много просмотров и детских просмотров)

Просто интересно, есть ли лучший способ добавления фрагмента, не жертвуя отзывчивостью пользовательского интерфейса. Спасибо за ваше время чтения постановки вопроса

+0

Вы действительно должны попытаться уменьшить текущую иерархию представлений. Макет фрагмента, который вы разместили, находится на 8 уровнях, и будет добавлено больше уровней из-за структуры фреймов + макета активности, который является плохим. – Luksprog

+0

Хм, да, я думал о сокращении взглядов и разделении его на новый фрагмент, чтобы облегчить загрузку пользовательского интерфейса на фрагмент. Но просто интересно, ошибался ли я в своем коде, что заставляет его загружаться так долго, как обычно. –

ответ

1

Решения: первую очередь вы разрабатываете класс фрагмента активности, в котором вы создаете функцию и добавить некоторые фрагменты. После менеджера фрагментов вы можете изменять фрагменты.

private List<Fragment> getFragments() { 
     List<Fragment> fList = new ArrayList<Fragment>(); 

     // TODO Put here your Fragments 
     Category_fragments f3 =new Category_fragments(); 
     Popular_fragments2 f2 = new Popular_fragments2(); 
     Random_fragments f4 = new Random_fragments(); 
     Recent_fragments2 f1 = new Recent_fragments2(); 
     fList.add(f1); 
     fList.add(f2); 
     fList.add(f3); 
     fList.add(f4); 
     return fList; 
    } 
Смежные вопросы