Building an Native Extension for Android, I'm trying to integrate the google mapview, which works well up to the point, when I try to access properties from the layout. The errors appears in the activity-class that extends the mapview:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_map);
mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true); // <- this crashes, same for textview etc.
The xml, that's loaded looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textfield1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="@string/hello_world"
android:textColor="#ff0000" />
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="300dp"
android:layout_height="300dp"
android:clickable="true"
android:apiKey="0cy94dNyuBcfF0aNZhB_JKpF4dQtxgDWhCXppRw" />
<Button
android:id="@+id/button_clear"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_width="100dp"
android:layout_height="40dp"
android:background="@android:color/black"
android:text="@string/clear"
android:textColor="@android:color/white" />
<Button
android:id="@+id/button_add"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_width="100dp"
android:layout_height="40dp"
android:background="@android:color/black"
android:text="@string/add"
android:textColor="@android:color/white" />
What I've found and checked so far:
I've read some posts about using getRessourceId, but that would imply the need to inject the FREContext into the activity, what sounds strange to me.
Any hints really appreciated! Thanx, M.
Figured the first part out. You actually have a static FREContext in you activity. In your extension function set this context with the one, you get:
@Override
public FREObject call(FREContext context, FREObject[] args) {
MyActivity.freContext = context;
In your activity, you set the layout by it's resourceId:
setContentView( freContext.getResourceId("layout.my_layout_xml"));
Hope this helps someone.