Android 使用带有弹出菜单的McClickListener

Android 使用带有弹出菜单的McClickListener,android,listview,android-arrayadapter,android-menu,Android,Listview,Android Arrayadapter,Android Menu,当我在自定义listview中单击某个项目时,我试图初始化弹出菜单。 我的McClick工作已通过日志记录确认 但是,我无法使弹出菜单在我的方法中工作。我不明白弹出菜单的正确上下文参数是什么 鉴于错误: error: incompatible types: <anonymous OnItemClickListener> cannot be converted to Context PopupMenu popup = new PopupMenu(this, positio

当我在自定义listview中单击某个项目时,我试图初始化弹出菜单。 我的McClick工作已通过日志记录确认

但是,我无法使弹出菜单在我的方法中工作。我不明白弹出菜单的正确上下文参数是什么

鉴于错误:

error: incompatible types: <anonymous OnItemClickListener> cannot be converted to Context
       PopupMenu popup = new PopupMenu(this, position);
我应该在这里传递什么参数?或者McClickListener是否与弹出菜单兼容

以下是完整的方法:

   private void populateUsersList() {
        // Construct the data source
        ArrayList<Issue> arrayOfUsers = ProfileActivity.getAllIssueList();
        // Create the adapter to convert the array to views
        issueAdapter adapter = new issueAdapter(this, arrayOfUsers);
        // Attach the adapter to a ListView
        final ListView listView = findViewById(R.id.listView);

      //populate the listView
       listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Get the selected item text from ListView
                Issue selectedItem = (Issue) parent.getItemAtPosition(position);
                Log.d("clicked",selectedItem.getIssueID());

                 PopupMenu popup = new PopupMenu(this, position);
                //Inflating the Popup using xml file
               popup.getMenuInflater().inflate(R.menu.popup_listview, popup.getMenu());

            }
        });
}
在嵌套类中,这是指嵌套类实例,而不是外部类实例MainActivity。使用例如MainActivity对其进行限定。这是指外部类实例:

PopupMenu popup = new PopupMenu(MainActivity.this, position);

谢谢,这对我有用!我会投票,但我需要一个更好的声誉分数…你为什么不使用?
PopupMenu popup = new PopupMenu(MainActivity.this, position);