我尝试使用此处的示例切换片段:
http://developer.android.com/guide/components/fragments.html
但它不起作用:
Fragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
我得到错误:
The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Fragment)
所以我解决了这个问题:
android.app.Fragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
并得到另一个错误,说 ExampleFragment 的类型错误,所以我将其更改为:
ExampleFragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
这一切都在循环中循环,解决方法是什么?