2016-09-17 163 views
-1

enter image description here显示弹出菜单时点击按钮

我有表演的弹出菜单问题,当我点击的布局,可以在任何一个有经验的帮我。

我想我的问题可能与我的主要活动,因为我与组视图使用,但我不知道如何解决这个问题的任何机构可以帮助我

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     context = getActivity().getApplicationContext(); 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.fg_dashboard__product__services, container, false); 
     rsview = (RecyclerView)view.findViewById(R.id.dashboard_product_service); 


     albumList = new ArrayList<>(); 
     adapter = new DashboardProductServiceAdapter(context, albumList); 

     RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(context, 1); 
     rsview.setLayoutManager(mLayoutManager); 
//  rsview.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true)); 
     rsview.setItemAnimator(new DefaultItemAnimator()); 
     rsview.setAdapter(adapter); 

     prepareAlbums(); 
     return view; 

    } 

这是我的点击动作

holder.layout.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       showPopupMenu(holder.layout); 
       Toast.makeText(mContext, "Click on layout", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

这是我的showPopupMenu函数。

public void showPopupMenu(View view) { 
     PopupMenu popup = new PopupMenu(mContext, view); 
     MenuInflater inflater = popup.getMenuInflater(); 
     inflater.inflate(R.menu.dashboard_context_menu, popup.getMenu()); 
     popup.setOnMenuItemClickListener(new MyMenuItemClickListener()); 
     popup.show(); 
    } 
+0

什么是乌拉圭回合的问题,我们的代码看起来很好 – darwin

+0

你的代码是好的,请检查是否已在其的onclick监听器或者你做了什么正在使用此功能是否正在传递正确的按钮 –

+0

如果出现任何错误,请发布错误日志。 – RamithDR

回答

0

现在我找到了解决方案,这个问题不是用xml文件,而是用java。

我使用:的

android.widget.PopupMenu popup = new PopupMenu(getApplicationContext(), view); 

代替:

PopupMenu popup = new PopupMenu(mContext, view); 
+0

这是我的正确解决方案 –

0

你的问题在Java代码中心不是很明显,一个XML格式的元素没有layout_height属性(可能在弹出菜单中,或者在R.menu.dashboard_context_menu一些其他元素)。检查这个文件,第17行是否有任何代码错误。

0

您需要在xml代码中定义“android:layout_height”属性。

相关问题