0

通常、次のようになります。

        Activity parent = (Activity) context;
                dragImage = (ImageView) parent.findViewById(R.id.what_ever_you_defined_on_xml);

ただし、私の場合、ユーザーがマップ上で必要とする OverlayItem の種類に応じて複数の属性があるため、「findViewById」で id 属性を動的に取得する必要があります (Open Street Map)。私はこれを試しましたが、アプリケーションがクラッシュしました:

        Activity parent = (Activity) context;
                View v = parent.getCurrentFocus();  
    dragImage = (ImageView) parent.findViewById(v.getId());

なにか提案を?ありがとう。


コンテキストを追加する詳細:

public Itemizedoverlay(Drawable defaultMarker, Context context, MapView map) {

super(defaultMarker, new DefaultResourceProxyImpl(context));
this.defaultMarker = defaultMarker;

this.map = map;

// Setup for dragging:
// Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle):

Activity parent = (Activity) context;
View v = parent.getCurrentFocus();  
dragImage = (ImageView) parent.findViewById(v.getId());

xDragImageOffset = dragImage.getDrawable().getIntrinsicWidth() / 2;
yDragImageOffset = dragImage.getDrawable().getIntrinsicHeight();
}

XML では:

<ImageView 
    android:id="@+id/drag1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/symbol1"
    android:visibility="gone"
    /> 

    <ImageView 
    android:id="@+id/drag2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/symbol2"
    android:visibility="gone" />

    <ImageView 
    android:id="@+id/drag3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/symbol3"
    android:visibility="gone"
    /> 

    <ImageView 
    android:id="@+id/drag4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/symbol4"
    android:visibility="gone"
    /> 
4

1 に答える 1

0

あなたの最終結果は単に以下と同じものをもたらすでしょうか:

dragImage = (ImageView)v;
于 2011-11-10T20:03:28.757 に答える