![](/img/trans.png)
[英]onResume() is not called in SherlockFragment of SherlockFragmentActivity in Android?
[英]Android SherlockFragmentActivity call SherlockFragment
最初,我有2个活动。 一个电话B活动。 现在我改变了A类扩展SherlockFragmentActivity和B类扩展了SherlockFragment。
我尝试在A类中更改这些:
private class MyTabListener implements ActionBar.TabListener {
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getPosition()==1) {
B frag = new B();
ft.replace(android.R.id.content, frag);
}
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
// =============================
在B班:
public class Br extends SherlockFragment{
/* Called when the activity is first created */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.promotionslist_tableview);
//get our listview
ListView myListView = (ListView) findViewById(R.id.myListView_promotionslist_table);
// ==============================
但错误。 1. onCreate 2. findViewById ..
我错了什么?
请给我一些提示。 谢谢。
我现在可以显示B fragement,但listview重叠在主列表视图上..? 为什么?
public class B extends SherlockFragment{
View view;
/* Called when the activity is first created */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//setContentView(R.layout.promotionslist_tableview);
//get our listview
ListView myListView = (ListView) view.findViewById(R.id.myListView_promotionslist_table);
.
.
.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.promotionslist_tableview, container, false);
return view;
}
您必须在片段中使用onCreateView()
方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout, null);
return view;
}
在那里你可以膨胀视图并调用findViewById,如下所示:
view.findViewById(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.