自分のビューの1つにマップビューを統合したい。android studio onMapReadyが呼び出されていない
私は新しいマップフラグメントを生成しました。それは別の視点で登場し、魅力のように機能します。
次に、コードを通常のアクティビティ(アクションバーなどのコード)に統合しようとしました。ちょっとした作品 - 画面上に表示されますが、onMapReadyはその環境で呼び出されることはありません(言い換えれば、私はシドニーに行くのではなく、アフリカで立ち往生しています)。時間のためにそれにされて
...ここ
はXMLコードです:
public class MonumentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monument);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(MapsActivity.this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
}
:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jp.artfoundui.MapsActivity" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/monument_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_camera" />
そしてここでは、Javaコードであります
何か提案がありますか?
私はこれはダムと思っていますが、実際にはデバッガを使用して、 onMapReady()に挿入しますか?私は私の個人的なコードのいくつかを見ており、私たちの仕事は基本的に一致しています。おそらくonMapReadyの中に何かがありますが、それは動作していませんか? –
良い提案。私は、ええと、onMapReadyへの呼び出しをチェックしました。 – jpberry
しかし、私がデバッガで遊んでいたときに、onCreateが呼び出されないことに気がつきました。当然、onMapReadyは決して登録されません。 これで、なぜonCreateが呼び出されないのですか?私は他のデモコード(画面上の断片をちょうど抜く標準的な例)をチェックし、onCreateは実際に呼び出されます。しかし、いったん私の活動(上記のコード)にフラグメントを配置すると、onCreateは呼び出されません。 – jpberry