2012-11-27 51 views
1

爲Android構建原生擴展,我試圖集成google mapview,當我試圖從佈局中訪問屬性時,該功能非常有效。這些錯誤出現在擴展的MapView活動類:Adob​​e本機擴展Android版式xml無法訪問

@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. 

的XML,這是裝這個樣子的:

<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" /> 

我已經找到並檢查了迄今:

  • 擴展程序正確加載,因爲xml佈局中的地圖視圖正確顯示
  • res-folder被複制並編譯到ANE(解壓縮選中)以及APK(解壓縮選中)
  • 所有佈局元素都存在問題,應用程序在訪問textview時也崩潰了。因此,這不是一個特定地圖的問題,單機運行時
  • 項目工作正常,所以它一定是關於擴展

我讀過一些帖子關於使用getRessourceId的東西,但是這將意味着需要將FREContext注入活動中,這聽起來很奇怪。

任何提示真的很感激! Thanx,M.

回答

1

第一部分出來了。你的活動中實際上有一個靜態FREContext。在設置這個上下文中有一個你的擴展功能,您可以:

@Override 
    public FREObject call(FREContext context, FREObject[] args) { 

     MyActivity.freContext = context; 

在你的活動,你設置佈局由它的RESOURCEID:

setContentView(freContext.getResourceId("layout.my_layout_xml")); 

希望這可以幫助別人。