[英]Android SherlockFragmentActivity call SherlockFragment
Originally, I have 2 Activities. 最初,我有2个活动。 A call B activities.
一个电话B活动。 Now I changed the A class extends SherlockFragmentActivity and B class extends SherlockFragment.
现在我改变了A类扩展SherlockFragmentActivity和B类扩展了SherlockFragment。
I tried to changed these in A class: 我尝试在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
}
}
//============================= // =============================
In B class: 在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);
//============================== // ==============================
BUT ERROR. 但错误。 1. onCreate 2. findViewById..
1. onCreate 2. findViewById ..
What i am wrong ? 我错了什么?
please give me some hints. 请给我一些提示。 Thanks.
谢谢。
I can now display the B fragement but the listview overlap on the main listview..? 我现在可以显示B fragement,但listview重叠在主列表视图上..? Why ?
为什么?
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;
}
You have to use the onCreateView()
method in fragments: 您必须在片段中使用
onCreateView()
方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout, null);
return view;
}
There you can inflate a View and call findViewById like this: 在那里你可以膨胀视图并调用findViewById,如下所示:
view.findViewById(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.