0
에서 조각에 containerViewId에 조각을 추가 안드로이드는 - 나는 다음과 같은 문제에 직면하고있어 ViewPager
MainActivity
Fragment
)를 통해 밀어 수있는
ViewPager
입니다. 이 카드에는 런타임 중에 다른 내용 (
Fragment
)이 삽입되는 자리 표시 자
ViewGroup
이 있습니다. 문제는 콘텐츠가 하나의 카드에만 배치된다는 것입니다.
MainActivity
public class MainActivity extend FragmentActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// ...
// init ViewPager
getViewPager().setAdapter(new CardSelectionAdapter(getSupportFragmentManager()));
}
// ...
private class CardSelectionAdapter extends FragmentPagerAdapter {
// ...
public Fragment getItem(int position) {
return new CardFragment(someData);
}
}
}
CardFragment
나는 모든 카드MainActivity
에 속해 있기 때문에,
FragmentTransaction
만
id R.id.actionSheet
하나
ViewGroup
에 추가 할 수있는 생각
public class CardFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.card, container, false);
rootView.findViewById(R.id.actionSheet).setVisibility(View.GONE);
return rootView;
}
public void populate() {
// ...
Fragment f;
switch (type) {
case TYPE_A: f = new ActionsAFragment(); break;
case TYPE_B: f = new ActionsBFragment(); break;
default: f = null;
}
if (f != null) {
// Here should be the main problem when adding Fragment to container/placeholder
getFragmentManager().beginTransaction().add(R.id.actionSheet, f).commit();
getView().findViewById(R.id.actionSheet).setVisibility(View.VISIBLE);
}
}
}
.
같은 ID의 레이아웃에 콘텐츠를 추가하는 방법은 다른가요?
'getChildFragmentManager()'가 내 문제를 해결했습니다. 감사! BTW'populate()'는 어떤 데이터가 수신 될 때'BroadCastReceiver'에 의해 호출됩니다. 정보 유출 죄송합니다. –