import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fr=getFragmentManager();
FragmentTransaction fragmenttransaction=fr.beginTransaction();
fragmentHome home = new fragmentHome();
fragmenttransaction.add(android.R.id.content,home);
fragmenttransaction.commit();`
在这个主要活动中,我使用 android.app 库用于片段管理器和 fragmentTransaction ,但它仍然给出错误FragmentTransaction 类型fragmentTransaction.add
中的方法add(int, Fragment)
不适用于参数
(int,fragmentHome)
该怎么办,如何避免这种情况?
这是我的片段类
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class fragmentHome extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.home_fragment,container,false);
}
}
`