我使用了以下段来event_attendee GET /event_attendees/:id(.:format) event_attendees#show
PATCH /event_attendees/:id(.:format) event_attendees#update
PUT /event_attendees/:id(.:format) event_attendees#update
DELETE /event_attendees/:id(.:format) event_attendees#destroy
替换FrameLayout
Fragment
方法,
onNavigationItemSelected
我想用public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
Fragment fragment;
if (id == R.id.nav_camara) {
fragment = new MyFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.mainFrame, fragment);
ft.commit();
}
else if (id == R.id.nav_gallery) {
}
else if (id == R.id.nav_slideshow) {
}
else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
}
替换FrameLayout
,然后我做了
FragmentActivity
但在FragmentActivity fragmentAc;
if (id == R.id.nav_camara) {
fragmentAc= new MyFragmentActivity();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.mainFrame, fragmentAc);
ft.commit();
}
Wrong 2nd argument type. Found: 'android.support.v4.app.FragmentActivity', required: 'android.app.Fragment'
我现在应该改变什么,帮帮我
答案 0 :(得分:0)
您正试图将FragmentActivity
传递到需要Fragment
的位置,这就是错误所在。
如果您想要打开其他活动而不是替换片段,则必须致电startActivity(...)
取代:
if (id == R.id.nav_camara) {
fragmentAc= new MyFragmentActivity();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.mainFrame, fragmentAc);
ft.commit();
}
使用:
if (id == R.id.nav_camara) {
startActivity(new Intent(getActivity(), MyFragmentActivity.class));
}