The thing is i'm creating a honeycomb app and i can't switch between fragments . Here's my main code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (ListView)findViewById(R.id.list);
A = new FragmentA();
B = new FragmentB();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
list.setAdapter(adapter);
list.setOnItemClickListener(mylistener);
}
public void changeFragment(Fragment f){
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment, f);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
public OnItemClickListener mylistener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
switch(position){
case 0 : changeFragment(A);
break;
case 1 : changeFragment(B);
break;
}
}
};
I know before i put a "replace" i have to remove but how can i remove the one i'm already in ? What is telling me in the log : The specified child already has a parent. You must call removeView() on the child's parent first .