1

カスタム ItemizedOverlay クラスの AlertDialog から、どのアクティビティ (クラス名) がカスタム ItemizedOverlay クラスを開始したかを調べる方法を知りたいです。さまざまな場所の MapView でさまざまな活動をしています。MapView が読み込まれると、すべてのアクティビティが自動的に ItemizedOverlay クラスを開始します。そのため、Extra を意図することはできません。

これが可能かどうか誰にもわかりますか?

これが私の ItemizedOverlay コンストラクター クラスです (コメント部分と alertdialog メッセージ部分は無視してください):

public class CustomItemisedOverlay extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

private Context context;

public CustomItemisedOverlay(Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
    // TODO Auto-generated constructor stub
}

public CustomItemisedOverlay(Drawable defaultMarker, Context context) {
    this(defaultMarker);
    this.context = context;
}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return mapOverlays.get(i);
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return mapOverlays.size();
}

//AlertDialog for driving directions here
@Override
protected boolean onTap(int index) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    //Title of AlertDialog
    dialog.setTitle("Driving Directions");
    //Message of AlertDialog
    String className = getClass().getSimpleName().toString();
    dialog.setMessage(className);
    //Positive Button
    dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Handle launch of driving directions here
            /*String tappedLong = null;
            String tappedLat = null;
            String className = this.getClass().getSimpleName().toString();
            if(className == "amkActivity") {
                tappedLong = "1.363414";
                tappedLat = "103.9370256";

            } else if (className == "bedokActivity") {
                tappedLong = "1.3248498";
                tappedLat = "103.9370256";
            }


            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                    Uri.parse("http://maps.google.com/maps?daddr=" + tappedLat + "," + tappedLong));
            context.startActivity(intent);*/

        }
    });

    //Negative Button
    dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.cancel();
        }
    });
    //Display AlertDialog when tapped
    dialog.show();
    return true;
}

public void addOverlay(OverlayItem overlay) {
    mapOverlays.add(overlay);
    this.populate();
}

}

4

2 に答える 2

0

使用する

mapView.getContext();

itemizedoverlay..のコンストラクターで

これにより、マップビュー ページのコンテキストが返されます...

于 2012-08-06T08:18:35.743 に答える
0

これがどのように機能するかはよくわかりませんが、CustomItemisedOverlay クラスを開始したアクティビティの名前を取得するには、次を使用します

context.getClass().getSimpleName();

たとえば、アクティビティ名を className という文字列に入れたい場合は、次のようにします。

String className = context.getClass().getSimpleName().toString();

が使用される理由contextは、次のコード行のためです (上記を参照)。

private Context context;

したがってcontext、ここでは、CustomItemisedOverlay クラスを開始したアクティビティのコンテキストを参照します。

于 2012-08-07T02:07:57.043 に答える