0

제목에 대한 기존 답변에서 언급 한 솔루션을 시도한 후에도 동일한 오류가 지속되는 것 같습니다. NavigationBar에서 사용중인 사용자 정의 ArrayAdapter에서 Fragment를 부풀려합니다. 내가 팽창하려고하는 조각은 2 중첩 된 조각 자체를 가지고 있습니다. 내 직감은 LinearLayout에서 팽창하려고하는 것과 관련이 있다고하지만이 파편을 부 풀릴 수는 없습니다. 도움말 크게 감사하겠습니다. 여기 중첩 된 단편이있는 AdapterView에서 addView()가 지원되지 않습니다.

여기서 에러 로그

10-14 21:22:57.209: E/AndroidRuntime(30555): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inviscidlabs.schooled/com.inviscidlabs.schooled.ActivityClassEdit}: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.ActivityThread.access$800(ActivityThread.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.ActivityThread$H.handleMessage(ActivityThread.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.os.Handler.dispatchMessage(Handler.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.os.Looper.loop(Looper.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.ActivityThread.main(ActivityThread.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at java.lang.reflect.Method.invokeNative(Native Method) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at java.lang.reflect.Method.invoke(Method.java:515) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at dalvik.system.NativeStart.main(Native Method) 
10-14 21:22:57.209: E/AndroidRuntime(30555): Caused by: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.widget.AdapterView.addView(AdapterView.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.view.LayoutInflater.inflate(LayoutInflater.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.view.LayoutInflater.inflate(LayoutInflater.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.view.LayoutInflater.inflate(LayoutInflater.java) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at com.inviscidlabs.schooled.ContainerFragmentCriteria.onCreateView(ContainerFragmentCriteria.java:28) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:571) 
10-14 21:22:57.209: E/AndroidRuntime(30555): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java) 

이다 불쾌감 엔티티로 시작 코드이다

public class ContainerFragmentCriteria extends Fragment{ 



    private FragmentManager fm; 

    private boolean insertMode; 

    //=====================ACTIVITY LIFECYCLE============================== 
      @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
       View v = inflater.inflate(R.layout.frag_container_criteria, container); 
       return v; 
      } 


     @Override 
     public void onCreate(Bundle savedInstanceState){ 
      super.onCreate(savedInstanceState); 

      //Instantiate Fragments, set Arguments 
      FragmentCriteriaEdit fCrE= new FragmentCriteriaEdit(); 
      FragmentCriteriaList fCrL = new FragmentCriteriaList(); 

      Bundle fCritListArguments = new Bundle(); 
      fCritListArguments.putBoolean(CM.BKEY_INSERTMODE, insertMode); 
      //Begin the Transaction 
      fm=getChildFragmentManager(); 
      FragmentTransaction ft = fm.beginTransaction(); 
      ft.add(R.id.fccr_rootLayout, fCrE, FragmentCriteriaEdit.sTag); 
      ft.add(R.id.fccr_rootLayout, fCrL, FragmentCriteriaList.sTag); 
      ft.commit(); 

     } 

     @Override 
     public void onStart() { 
      super.onStart(); 
     //Get our arguments 
      Bundle args = getArguments(); 
      if(args!=null){ 
       insertMode=args.getBoolean(CM.BKEY_INSERTMODE); 
      } 
     } 

     @Override 
     public void onDetach() { 
      super.onDetach(); 

      try { 
       Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager"); 
       childFragmentManager.setAccessible(true); 
       childFragmentManager.set(this, null); 

      } catch (NoSuchFieldException e) { 
       throw new RuntimeException(e); 
      } catch (IllegalAccessException e) { 
       throw new RuntimeException(e); 
      } 
     } 



} 

어댑터 뷰 AdapterView.

활동 :

public class ActivityClassEdit extends FragmentActivity{ 

//Variables 
    //Fragments 
    private ContainerFragmentCriteria frag_Criteria; 


    private DrawerLayout mDrawerLayout; 
    private ListView mDrawerList; 
    private ActionBarDrawerToggle mDrawerToggle; 


    //used as the effective ArrayAdapter for the NavigationDrawer 
    private ClassEditDrawerAdapter mNavAdapter; 
    private CharSequence sDrawerTitle; 
    private CharSequence sTitle; 

    //Serves as List of Strings to populate Nav Drawer's ListView of options 
    List<ClassEditDrawerItem> navOptions; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.activity_classedit); 

      //Initialize List 
      navOptions= new ArrayList<ClassEditDrawerItem>(); 
      sTitle=sDrawerTitle=getTitle(); 

      mDrawerLayout = (DrawerLayout) findViewById(R.id.ace_drawer); 
      mDrawerList=(ListView) findViewById(R.id.ace_drawer_list); 

      navOptions.add(new ClassEditDrawerItem("Criteria", R.drawable.ic_launcher)); 

      mNavAdapter = new ClassEditDrawerAdapter(this, R.layout.item_basic, navOptions); 
      mDrawerList.setAdapter(mNavAdapter); 
      //Set ListView onClickListener 
      mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 

      //Set up the home button to open the nav drawer 
      getActionBar().setDisplayHomeAsUpEnabled(true); 
      getActionBar().setHomeButtonEnabled(true); 

      mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
        R.drawable.ic_launcher, R.string.hello_world, 
        R.string.name); 

      mDrawerLayout.setDrawerListener(mDrawerToggle); 

      //Select first item by default 
      if(savedInstanceState==null){ 
       SelectItem(0); 
      } 




    } 

    @Override 
    public void setTitle(CharSequence title) { 
      sTitle = title; 
      getActionBar().setTitle(sTitle); 
    } 

    @Override 
    protected void onPostCreate(Bundle savedInstanceState) { 
      super.onPostCreate(savedInstanceState); 
      // Sync the toggle state after onRestoreInstanceState has occurred. 
      mDrawerToggle.syncState(); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
      // The action bar home/up action should open or close the drawer. 
      // ActionBarDrawerToggle will take care of this. 
      if (mDrawerToggle.onOptionsItemSelected(item)) { 
       return true; 
      } 

      return false; 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
      super.onConfigurationChanged(newConfig); 
      // Pass any configuration change to the drawer toggles 
      mDrawerToggle.onConfigurationChanged(newConfig); 
    } 

    //What to do when Item is Selected 
    public void SelectItem(int position){ 
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 

     switch(position){ 
     //Class Edit 
     case 0: 
      if(frag_Criteria==null){ 
       frag_Criteria = new ContainerFragmentCriteria(); 
      } 
      transaction.replace(R.id.ace_drawer_list, frag_Criteria); 
      transaction.commit(); 
      break; 


     } 

     Toast.makeText(this, String.valueOf(position), Toast.LENGTH_LONG).show(); 
    } 


    private class DrawerItemClickListener implements ListView.OnItemClickListener { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, 
        long id) { 
       SelectItem(position); 
     } 
    } 

} 

마지막으로, XMLS :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/fccr_rootLayout" 
    android:orientation="vertical" > 


</LinearLayout> 
</RelativeLayout> 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout android:id="@+id/item_ace_itemlayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:orientation="vertical" 
     android:background="?android:attr/activatedBackgroundIndicator" 
     > 
     <LinearLayout 

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:minHeight="55dp" 
       > 

        <ImageView 
         android:id="@+id/drawer_icon" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         /> 

        <TextView 
         android:id="@+id/drawer_itemName" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textAppearance="?android:attr/textAppearanceLarge" 

         /> 
       </LinearLayout> 

     <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_marginBottom="1dp" 
     android:layout_marginTop="1dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:background="#DADADC" 

     ></View> 

    </LinearLayout> 


</RelativeLayout> 

그리고 활동의 XML :

레이아웃을 팽창 할 때 내가 null로 부모보기 인수를 설정 주목
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/ace_drawer" > 

    <FrameLayout android:id="@+id/ace_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

    <ListView 
     android:id="@+id/ace_drawer_list" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     /> 


</android.support.v4.widget.DrawerLayout> 
+0

당신이 null을 사용하려는 경우 루트 뷰는 세 번째 매개 변수를 사용하지 않습니다. 그건 상관 없어요. 'inflater.inflate (layoutResID, null); ' –

답변

2

내 직감은 LinearLayout에서 팽창하려고하는 것과 관련이 있다는 것을 알았지 만 이러한 조각을 팽창시킬 수는 없습니다.

두 가지 일이 잘못되어 예외가 발생합니다. 우선, selectItem()을 통해 ContainerFragmentCriteria 프래그먼트를 추가하는 작업에서는 R.id.ace_drawer_list이있는 컨테이너에 프래그먼트를 배치하는 트랜잭션을 사용합니다. 이드는 내비게이션 ListView에 해당합니다. ListView에 단편을 추가 할 수 없기 때문에 실패합니다. ace_frame FrameLayout (목록 대신 단편을 추가할까요?))과 같은 보관 컨테이너가 필요합니다.

두 번째로, 조각 트랜잭션에서 ListView의 ID를 사용하면 프레임 워크에서 (나중에) addView()이라는 조각의보기를 해당 컨테이너에 추가합니다. addView()를 통해 자식을 직접 추가하는 것은 ListView (및 AdapterView의 모든 하위 클래스)에서 지원되지 않습니다. 조각의 onCreateView()에서는 조각 레이아웃을 팽창하고 당신은 또한 (ListView에 인), 대신,이 작업을 수행해서는 안 컨테이너 매개 변수에 추가 :

View v = inflater.inflate(R.layout.frag_container_criteria, container, false);// false to not add the inflated layout to container 
+0

답변으로 표시. 이전 오류가 완화됩니다. 그러나, 이제 "지정된 자식이 이미 부모 오류가 있습니다." 보기를 부 풀릴 것에 대한 통찰력을 주셔서 감사합니다. –

+0

@JoshRibeiro 새 질문을 게시하십시오. 코드를 수정 한 방법을 보지 않고 실제로 어떤 예외로 새로운 예외가 발생 하는지를 보지 않고 무엇이 잘못되었는지를 말하기는 어렵습니다. – Luksprog