2013-07-05 192 views
0

如何在popup菜單項點擊開始新的意圖。以下是我試過的代碼:onitemclicklistener彈出式菜單

public class Profile extends Fragment { 
    public Profile() { } 

    View vi; 
    public static final String ARG_SECTION_NUMBER = "section_number"; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     vi = inflater.inflate(R.layout.profile, container, false); 
     TextView iv = (TextView) vi.findViewById(R.id.btnprofile_settings); 

     iv.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       PopupMenu homepopup = new PopupMenu(getActivity(), v); 
       MenuInflater inflater = homepopup.getMenuInflater(); 
       inflater.inflate(R.menu.account_settings, homepopup.getMenu()); 

       homepopup.show(); 
      } 
     }); 
     return vi; 
    } 
} 

任何想法?

感謝,

回答

1

你必須在PopupMenu實例中使用setOnMenuItemClickListener像:

homepopup.setOnMenuItemClickListener(new OnMenuItemClickListener() { 

     @Override 
     public boolean onMenuItemClick(android.view.MenuItem item) { 
      return true; 
     } 
    })