Reputation: 97
Originally, I have 2 Activities. A call B activities. Now I changed the A class extends SherlockFragmentActivity and B class extends SherlockFragment.
I tried to changed these in A class:
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:
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..
What i am wrong ?
please give me some hints. Thanks.
Upvotes: 0
Views: 2621
Reputation: 97
I can now display the B fragement but the listview overlap on the main 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;
}
Upvotes: 2
Reputation: 72653
You have to use the onCreateView()
method in fragments:
@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:
view.findViewById(...);
Upvotes: 0