Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package antonmatveyenka.testapp;
- import android.app.Activity;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentActivity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import com.google.android.gms.maps.CameraUpdateFactory;
- import com.google.android.gms.maps.GoogleMap;
- import com.google.android.gms.maps.MapView;
- import com.google.android.gms.maps.MapsInitializer;
- import com.google.android.gms.maps.OnMapReadyCallback;
- import com.google.android.gms.maps.SupportMapFragment;
- import com.google.android.gms.maps.model.LatLng;
- import com.google.android.gms.maps.model.MarkerOptions;
- public class TestFragment extends Fragment implements OnMapReadyCallback, View.OnClickListener {
- private MainActivity MA;
- private MapView mMapView;
- private GoogleMap googleMap;
- private Button buttonToSwitch;
- public TestFragment() {};
- public void setMainActivity(MainActivity MA) {
- this.MA = MA;
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_layout, container, false);
- }
- @Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- this.getActivity().setTitle("Мероприятия");
- this.buttonToSwitch = (Button) view.findViewById(R.id.button);
- this.buttonToSwitch.setOnClickListener(this);
- mMapView = (MapView) view.findViewById(R.id.mapView);
- mMapView.onCreate(savedInstanceState);
- mMapView.onResume();
- try {
- MapsInitializer.initialize(getActivity().getApplicationContext());
- } catch (Exception e) {
- e.printStackTrace();
- }
- mMapView.getMapAsync(this);
- }
- @Override
- public void onResume() {
- super.onResume();
- mMapView.onResume();
- }
- @Override
- public void onPause() {
- super.onPause();
- mMapView.onPause();
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- mMapView.onDestroy();
- }
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mMapView.onLowMemory();
- }
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
- @Override
- public void onMapReady(GoogleMap googleMap) {
- this.googleMap = googleMap;
- LatLng Pinsk = new LatLng(52.1313878, 26.1099338);
- this.googleMap.addMarker(new MarkerOptions()
- .position(Pinsk)
- .title("Пинск, стадион ДОСААФ"));
- this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(Pinsk));
- }
- @Override
- public void onClick(View view) {
- this.MA.replaceFragment();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement