2016-09-17 127 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」屬性。

相關問題