I have a view that shows a List of Properties, at the bottom of the screen there's a button that opens a fragment containing a MapView.
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.find_property_btn_map:
PropertyMapFragment fragment = PropertyMapFragment.newInstance(false, null);
getActivity().getSupportFragmentManager().beginTransaction()
.addToBackStack(null)
.replace(((ViewGroup) getView().getParent()).getId(), fragment, PropertyMapFragment.class.getSimpleName())
.commit();
break;
}
}
The onCreateView method for my Properties fragments is as follows
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(R.layout.fragment_properties_list, container, false);
getmBtnMap().setOnClickListener(this);
getmBtnSaveSearch().setOnClickListener(this);
getmBtnSort().setOnClickListener(this);
getmListView().setAdapter(getPropertyAdapter());
getmListView().setOnItemClickListener(this);
getmListView().setOnScrollListener(this);
getmListView().setScrollingCacheEnabled(false);
searchProperties();
return mRootView;
}
searchProperties();
takes care of calling a Web Service and filling the ArrayAdapter
.
The thing is that, when I open the MapFragment
and then press the back button, my Property fragment
is blank and the buttons do not respond to onClick
events.
I tried debugging and saw that onCreateView()
is being called when coming back to Property fragment
, but the buttons are no longer working and the listview
is nowhere to be seen.
What am I doing wrong?