@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
btnnext3=(Button) view.findViewById(R.id.button1);
btnnext3.setOnClickListener(new OnClickListener() {
private Context CurrentObj=getActivity();
@Override
public void onClick(View view) {
Intent redirect=new Intent(CurrentObj,FurnitureFragment.class);
CurrentObj.startActivity(redirect);
}
});
return view;
}
这里没有重定向。点击按钮应用程序停止。使用Android工作室。它是一个片段类
logcat的:
E / AndroidRuntime(1952):android.content.ActivityNotFoundException: 无法找到显式活动类 {info.androidhive.navigationdrawer / info.androidhive.navigati ondrawer.fragment.Fu rnitureFragment}; 你有没有在AndroidManifest.xml中声明这个活动? 07-11 03:59:47.370:E / AndroidRuntime(1952):at android.app.Instrumentation.checkStartActivityResult(仪器厂entation.java:1628)
答案 0 :(得分:0)
您正在通过意图调用片段。这不可能发生。因为片段必须附加或分离到Activity.Please看看这个以便更好地理解: Fragments
替换您的代码:
Intent redirect=new Intent(CurrentObj,FurnitureFragment.class);
CurrentObj.startActivity(redirect);
有了这个:
FurnitureFragment fragment2 = new FurnitureFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, fragment2);//Replace this with your layout ID.
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
检查出来: