0

地図を長くクリックしたときにポップアップウィンドウを作成したいのですが、ここに私のコードとpopup.xmlがあります:しかし、ポップアップウィンドウが表示されず、Logウィンドウが表示されていることがわかります。Constructorその上、 関数と関数には多くのバージョンがあり、showAtLocationそれらの違いについてはよくわかりません。誰かが私のコードの間違いを見つけることができますか? どうもありがとうございました!

private void init()
{
    mGMap = ((MapFragment)  getFragmentManager().findFragmentById(R.id.map))
            .getMap();
    if( mGMap != null )
    {
        mGMap.setMyLocationEnabled(true);

        mGMap.getUiSettings().setMyLocationButtonEnabled(true);
        mGMap.getUiSettings().setRotateGesturesEnabled(true);
        mGMap.getUiSettings().setCompassEnabled(true);
        mGMap. setOnMapLongClickListener (new GoogleMap.OnMapLongClickListener(){
            @Override
            public void onMapLongClick(LatLng point) {
                // TODO Auto-generated method stub
                View popup_view = getLayoutInflater().inflate(R.layout.popup, null);
                PopupWindow popupWindow = new PopupWindow(popup_view);              
                View parent =  ((MapFragment)  getFragmentManager().findFragmentById(R.id.map)).getView();
                WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                @SuppressWarnings("deprecation")
                int xoff = windowManager.getDefaultDisplay().getWidth() / 2 - popupWindow.getWidth() / 2;
                // 使其聚集
                popupWindow.setFocusable(true);
                // 设置允许在外点击消失
                popupWindow.setOutsideTouchable(false);
                popupWindow.showAtLocation(parent, Gravity.CENTER, xoff, 0);
                if(popupWindow.isShowing()){
                    Log.i(mainActivity.toString(), "pop up is showing");
                }
                popupWindow.update();
            }
        });
    }   

そして、以下は私の popup.xml です:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:id="@+id/location_time_tag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@string/loc_date" />

    <ListView
        android:id="@+id/listview_diary"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:smoothScrollbar="true"
        android:layout_below="@id/location_time_tag">
    </ListView>
    <EditText
        android:id="@+id/add_note"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/listview_diary"
        android:layout_alignParentLeft="true"
    />    
    <Button 
        android:id="@+id/add_text_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/add_note"
        android:layout_alignParentLeft="true"
        android:text="写日记"/>
    <Button 
        android:id="@+id/del_text_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/add_text_btn"
        android:layout_alignParentRight="true"
        android:text="删日记"/>
</RelativeLayout> 
4

1 に答える 1

0

ポップアップウィンドウが開いているとログが言っているので、ウィンドウに間違ったコンテキストを追加していることを意味します。ウィンドウは開いていますが、他のアクティビティまたは他のクラスで開いていることを意味します。適切なコンテキストをウィンドウに適用することをテストする必要があります。

于 2013-02-07T13:13:51.003 に答える