【发布时间】:2015-08-21 07:44:25
【问题描述】:
问题来了
我有一个Fragment 类DisplayFragment 并且我已经在content frame 中有一个节目,然后我做
DisplayFragment a = DisplayFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.replace(R.id.contentFrame, DisplayFragment)
.commit();
然后我想使用View v = a.getView(); 获得fragment 的view,但它返回null view。
谁能告诉我为什么?因为我必须更改新Fragment 的一些视图设置。
onCreateView() in DisplayFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_display, container, false);
//Some TextView setup
Button button = (Button) view.fineViewById(R.id.button);
return view; }
【问题讨论】:
-
可以添加
DisplayFragment的代码吗?我怀疑这是因为片段转换的延迟。 -
getSupportFragmentManager().beginTransaction() .replace(R.id.contentFrame, a); .commit();
标签: android android-fragments fragment android-view