我想在添加公寓类的apartment fragment
添加intent
这个选项菜单。在运行此代码时,我的应用程序崩溃,我可能错过了某些人可以帮助我,我该怎么办?
LandlordAddApartment.java
public class LandlordAddApartment extends Fragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Nullable
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.add_apartment, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.landlord_add_apartment) {
LanlordMapFragment mapFragment = new LanlordMapFragment();
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Manage Apartment");
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.landlord_add_apartment, container, false);
return v;
答案 0 :(得分:0)
您可以使用从Fragment
切换到Activity
:
startActivity(new Intent(getActivity,YourActivity.Class));
从Activity
转移到Fragment
时:
YourFragment mapFragment = new YourFragment();
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();