基于条件的某些项目上的Gridview上下文菜单

时间:2019-07-18 19:31:07

标签: android android-layout

我正在通过API获取动态数据,以通过使用Retrofit来提供Gridview项目。我不想在gridview中的某些项目上应用(或显示)上下文菜单。在这里我可以调用 registerForContextMenu()(或执行其他操作)来完成此操作。

我试图通过应用条件在循环内调用registerForContextMenu(),但是上下文菜单仍然适用于所有项目。我看到了此解决方案Context menu in GridView Android,但不幸的是,它是基于项目的位置而不是其他参数的。


    @Override
    public void onResponse(@NonNull Call<List<PlacePOJO>> call, @NonNull Response<List<PlacePOJO>> response) {                    

        placeGridView =  findViewById(R.id.PlacegridView);

        List<PlacePOJO> places = response.body();

        if (places != null) {
            for (PlacePOJO placePOJO :places){
                PlaceView placeView = new PlaceView();

                if (places.etEtatPlace() == EtatPlace.EnAttente.ordinal())
                {
                    registerForContextMenu(placeGridView);
                }

                //some codes removed for simplicity
            }
        }

        //some codes removed for simplicity
    }
});

0 个答案:

没有答案
相关问题