2013-01-01 3 views
0

제목에서 볼 수 있듯이 같은 컨테이너에 2 개의 동일한 조각을 추가하려고합니다. 조각을 사용하여 조각을 추가하고 있습니다. 처음 작동하지만 두 번째 조각을 추가하려고하면 조각이 교체됩니다. 여기 동일한 컨테이너에 동일한 조각 2 개를 추가하십시오.

public void addNewCategoryFragment(Category c) { 
FragmentManager fragmentManager = getFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager 
     .beginTransaction(); 
CategoryFragment categoryFragment = new CategoryFragment(c.name); 
fragmentTransaction.add(R.id.fragment_root, categoryFragment, String.valueOf(c.getID())); 
fragmentTransaction.commit(); 
} 

내가에 조각을 추가 할 노력하고있어 XML의 :

가 여기 내뿐만 아니라 코드의 자바 잘 보이는 눈에

<LinearLayout 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" 
    android:background="@drawable/school" 
    android:orientation="vertical" 
    tools:context=".MainActivity" > 

<LinearLayout 
    android:id="@+id/fragment_root" 
    android:layout_width="match_parent" 
    android:layout_height="413dp" 
    android:orientation="vertical" > 
</LinearLayout> 

<FrameLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<Button 
    android:id="@+id/submit_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|right" 
    android:text="Submit" /> 

<Button 
    android:id="@+id/new_category_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|left" 
    android:onClick="createNewCategory" 
    android:text="New Category" /> 
</FrameLayout> 
+0

태그를 사용되지 않기 때문에

<LinearLayout android:id="@+id/fragment_root" android:layout_width="match_parent" android:layout_height="413dp" android:orientation="vertical" android:isScrollContainer="true"> </LinearLayout> 

나는 또한 레이아웃의 나머지 부분에서 "match_parent"와 "fill_parent"값을 대체 할 것 value (귀하의 경우에는'String.valueOf (c.getID())')가 달라야합니다. 그렇지? – dmon

+0

예. addNewCategoryFragment는 Category를 인수로 취합니다. ORM으로 android-active-record를 사용하고 있으므로 getID는 sqlite 데이터베이스의 카테고리 ID입니다. 기본 키이므로 고유합니다. –

답변

0

, 그것은 배치 될 수있다 . 당신의 단편의 레이아웃을 알지 못해도 말하기는 어렵지만, 제 추측은 단지 은폐되고 있다는 것입니다. 이 같은 사실에 isScrollContainer 그들 주위에있는 ScrollView를 넣어 또는 설정하십시오 : fill_parent가

+0

그것은 일했다! 감사. –

관련 문제