を表示するアプリに取り組んでいますContextMenu
。ここで、このメニュー項目の 1 つContextMenu
が押されたときに、 を表示したいと思いますPopupWindow
。インターネットで使用方法の例をいくつか見つけましPopupWindow
たが、まだ問題があります。次のコードがあります。
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupView.showAtLocation(this.findViewById(R.id.main_layout), Gravity.CENTER, 0, 0);
アクティビティの XML ファイルでは、次のようになります。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#232323" >
....
</RelativeLayout>
これでうまくいくはずだと思ったのですが、次のエラー メッセージが表示されます。
「メソッド showAtLocation(View, int, int, int) はタイプ View に対して定義されていません」
これは何を意味するのでしょうか?私は showAtLocation に View と 3 つの整数を与えていますよね? だから問題は何ですか?何かアイデアはありますか?