First I want to explain my layout. It is a "tab list in a tab" which means a list view is controlled by a tab and the tab list is controlled by another tab. Hope you can understand what I mean...
my two tab widgets:
(bottom tab: main control panel)
public class BottomTabWidget extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottom_tab);
FragmentTabHost tabHost = (FragmentTabHost)findViewById(R.id.bottom_tab_host);
tabHost.setup(this, getSupportFragmentManager(), R.id.bottom_tab_content);
View exploreView = LayoutInflater.from(this).inflate(R.layout.explore, null);
View browseView = LayoutInflater.from(this).inflate(R.layout.browse, null);
View profileView = LayoutInflater.from(this).inflate(R.layout.profile, null);
View cartView = LayoutInflater.from(this).inflate(R.layout.cart, null);
tabHost.addTab(tabHost.newTabSpec("explore").setIndicator(exploreView), ListTabWidget.class, null);
tabHost.addTab(tabHost.newTabSpec("browse").setIndicator(browseView), SearchList.class, null);
tabHost.addTab(tabHost.newTabSpec("profile").setIndicator(profileView), SearchList.class, null);
tabHost.addTab(tabHost.newTabSpec("cart").setIndicator(cartView), SearchList.class, null);
}
}
(list tab: only control the list view)
public class ListTabWidget extends Fragment{
//for extending Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedIntanceState){
//View view = inflater.inflate(R.layout.list_tab, container);
//FragmentTabHost tabHost = (FragmentTabHost)view.findViewById(R.id.list_tab_host);
FragmentTabHost tabHost = new FragmentTabHost(getActivity());
tabHost.setup(getActivity(), getChildFragmentManager(), R.id.listtabcontent);
View tabView = setTab(inflater, " New Items ");
tabHost.addTab(tabHost.newTabSpec("all_post").setIndicator(tabView), ListPost.class, null);
return tabHost;
}
private View setTab(LayoutInflater inflater, String text){
View tabView = inflater.inflate(R.layout.list_tab_text, null);
TextView textView = (TextView)tabView.findViewById(R.id.textView);
textView.setText(text);
return tabView;
}
}
code in ListPost
class (too long so I cut out the critical part)
listView = (ListView)this.getView().findViewById(android.R.id.list);
list = new CustomAdapter(this.getActivity() ,android.R.layout.simple_selectable_list_item, productArray);
listView.setAdapter(list);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Product item = (Product) parent.getItemAtPosition(position);
Bundle args = new Bundle();
args.putString("pid", item.getData(WPTemplateDB.PRODUCT_ID)+"");
//switchFragment(args);
new FragmentProcess().switchFragment(getActivity(), R.id.bottom_tab_content, new PostDetail(), args);
}
});
FragmentProcess
class
public class FragmentProcess {
public void switchFragment(FragmentActivity activity, int element, Fragment replaceFragment, Bundle args){
replaceFragment.setArguments(args);
FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
transaction.replace(element, replaceFragment);
transaction.addToBackStack(null);
transaction.commit();
}
}
The error (shown as title) occurs when I click the list view elements which means replacing fragment. What I did wrong??