我尝试使用此处的示例切换片段:
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();
这一切只是在循环中循环,是什么修复?
答案 0 :(得分:0)
您需要将支持库添加到项目中。这应该可以解决你的问题。撤消您所做的代码更改...在eclipse中,右键单击(或根据您的计算机选择单击)项目,然后转到Android工具>添加支持库...
清理并重建项目...应该修复所有错误。