【问题标题】:SherlockActionbar with Two Fragments inside of itSherlockActionbar 里面有两个片段
【发布时间】:2014-09-12 07:20:47
【问题描述】:
我有点困惑。基本上我有两个片段。 一个单一的 SherlockFragmentActivity 作为他们的容器。可以通过 Tab-Tab 访问。
每个片段都有自己的 XML(包含按钮、文本视图等的布局)。
通常在我使用 actionbar 之前,我将每个组件(按钮等、侦听器等)的声明放在 Main Activity(其容器)中。
我的问题是,
基于我上面的第一个案例。
我应该把组件操作的声明放在哪里?
是否在每个 Fragments 的 onCreateView() 方法内
还是我应该只把它放在主容器的 onCreate() 里面? -SherlockFragmentActivity
危险吗?
请分享一些指导。谢谢
【问题讨论】:
标签:
java
android
android-actionbar
actionbarsherlock
fragment
【解决方案1】:
在片段中:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
setHasOptionsMenu(true); //if you need it
return rootView;
}
@Override
public void onActivityCreated (Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
//here you do your "components manipulation"
// call getView().findViewById(...) for getting components
}