如何在popupmenu项目点击上启动新意图。以下是我尝试过的代码:
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;
}
}
有什么想法吗?
谢谢,
答案 0 :(得分:1)
您必须在setOnMenuItemClickListener
实例上使用PopupMenu
,例如:
homepopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(android.view.MenuItem item) {
return true;
}
})