Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i couldnt understand the way to show map inside fragments so i go up like this,</p> <pre><code>public class MapFragment extends Activity { // Google Map private GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapsview); try { // Loading map initilizeMap(); } catch (Exception e) { e.printStackTrace(); } } // function to load map. If map is not created it will create it for you private void initilizeMap() { if (googleMap == null) { googleMap = ((com.google.android.gms.maps.MapFragment) getFragmentManager() .findFragmentById(R.id.map)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! Unable to load map", Toast.LENGTH_SHORT).show(); } } // create marker and setting latitude and longitude MarkerOptions marker = new MarkerOptions() .position( new LatLng(Double.parseDouble(DetailActivity.Lat), Double.parseDouble(DetailActivity.Long))) .title(DetailActivity.name + " " + PriceFragment.actualprice.getText().toString() + " -- " + PriceFragment.dealPrice.getText().toString()); // adding marker googleMap.addMarker(marker); } public void onResume() { initilizeMap(); super.onResume(); // getLatLongValues(); } </code></pre> <p>The above class is an activity with the map .</p> <p>and now i am getting only the window of the activity inside my fragment .</p> <pre><code>public class MapExtend extends Fragment { private static final String KEY_STATE_BUNDLE = "localActivityManagerState"; private LocalActivityManager mLocalActivityManager; protected LocalActivityManager getLocalActivityManager() { return mLocalActivityManager; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle state = null; if (savedInstanceState != null) { state = savedInstanceState.getBundle(KEY_STATE_BUNDLE); } mLocalActivityManager = new LocalActivityManager(getActivity(), true); mLocalActivityManager.dispatchCreate(state); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // This is where you specify you activity class Intent i = new Intent(getActivity(), MapFragment.class); i.putExtra("lat", DetailActivity.Lat); i.putExtra("long", DetailActivity.Long); i.putExtra("name", DetailActivity.name); Window w = mLocalActivityManager.startActivity("tag", i); View currentView = w.getDecorView(); currentView.setVisibility(View.VISIBLE); currentView.setFocusableInTouchMode(true); ((ViewGroup) currentView) .setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); // View newView = inflater.inflate(currentView, container, false); // currentView.setId(R.layout.maplayout); // View newView = inflater.inflate(currentView.getId(), // container,false); return currentView; } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBundle(KEY_STATE_BUNDLE, mLocalActivityManager.saveInstanceState()); } @Override public void onResume() { super.onResume(); mLocalActivityManager.dispatchResume(); } @Override public void onPause() { super.onPause(); mLocalActivityManager.dispatchPause(getActivity().isFinishing()); } @Override public void onStop() { super.onStop(); mLocalActivityManager.dispatchStop(); } @Override public void onDestroy() { super.onDestroy(); mLocalActivityManager.dispatchDestroy(getActivity().isFinishing()); } </code></pre> <p>I got my map by using like this. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload