0

findViewByIdレイアウトにインクルードを使用すると、何に対しても null が返されるという奇妙な問題があります。

This is my onCreate(), アクティビティが拡張されますMapActivity

@Override
    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        setContentView(R.layout.main);
                // this will be null
        MapView myMapViewmyMapView = (MapView) findViewById(R.id.mapview);

    }

そして、これが私のレイアウトです。main.xml

<!-- Loads of other layout elements up here, buttons, headers etc-->
<LinearLayout android:layout_width="fill_parent"
                  android:id="@+id/demo_mode_layout"
                  android:orientation="vertical"
                  android:layout_height="wrap_content"
                  android:gravity="center_horizontal"
                  android:background="@drawable/panel"
                  android:layout_marginTop="5dp"
                  android:layout_marginBottom="5dp"
                  android:layout_marginLeft="5dp"
                  android:layout_marginRight="5dp">

        <!-- Include the mapview from an external mapview layout file-->
        <include android:id="@+id/header" layout="@layout/maps"/>
    </LinearLayout>

そして、私が参照しているマップビュー:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="my legit key here"
        />

私のアクティビティで、R.layout.mainそれを使用してコンテンツ ビューを設定すると失敗しますが、マップ エンティティだけに設定すると、R.layout.mapsすべて問題ありません。

ビューをスキンしてヘッダー、フッター、ボタンメニューなどを表示できるように使用したいのですR.layout.mainが、なぜこれが機能しないのですか?

4

1 に答える 1