0

如何在弹出菜单项单击上开始新的意图。以下是我尝试过的代码:

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;
    }
}

有任何想法吗?

谢谢,

4

1 回答 1

1

您必须setOnMenuItemClickListenerPopupMenu实例上使用,例如:

homepopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(android.view.MenuItem item) {
            return true;
        }
    })
于 2013-07-05T10:24:48.220 回答