As I am not familiar with Fragments I am getting quite confused with the solutions presented on stackoverflow. I have tried many different techniques to achive this task: I have a class called MapFragment that extends Fragment. It works fine inside my viewpager. However, I want to reuse this class from a different activity. Heres a sample from my Fragment called MapFragment:
public class MapFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_mapview, container, false);
mapView = (MapView) rootView.findViewById(R.id.fragment_mapView);
mapView.onCreate(savedInstanceState);
this.setHasOptionsMenu(true);
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
initGPS();
initViews();
initListeners();
Bundle extras = getArguments();
String url = "";
if(extras.containsKey("url"))
url = extras.getString("url");
new LoadMarkers().execute(url);
return rootView;
}
}
Let´s say I have another activity that I want to be used to reuse this mapfragment above:
public class MapActivity extends GeneralActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I want to be able to display the MapFragment inside this activity
// What Should I Do Here????
enter code here
}
}
Then I can from anywhere in my program call a intent on the MapActivity knowing it will display the MapFragment within it. Is this possible to be accomplished?