Reputation: 35
I have a problem with changing of popupmenu
title.
My goal is that there is a join menu in popupmenu
list.
After user join the app by using the popupmenu
button , I want to change the "join" title to "User profile".
But I don't know how to change the title of popupmenu
.
If there has a solution, let me know how to change.
Here is the code
<item android:id="@+id/menu6"
android:title="join"/>
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_menu://popupbutton
PopupMenu popup = new PopupMenu(getApplicationContext(), v);
getMenuInflater().inflate(R.menu.main_menu, popup.getMenu());
popup.setOnMenuItemClickListener(popupClick);
popup.show();
}
PopupMenu.OnMenuItemClickListener popupClick = new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuitem) {
switch (menuitem.getItemId()) {
case R.id.menu6: // here is a code of join
break;
}
Upvotes: 2
Views: 1529
Reputation: 12803
You can follow this answer Change PopupMenu items' title programatically .
First create a boolean variable
private boolean menu6;
Create a menu object to check which popup item is clicked
Menu menuOpts = popup.getMenu();
if (menu6) {
menuOpts.getItem(1).setTitle("User profile");
}
Modify onMenuItemClick
to this
switch (menuitem.getItemId()) {
case R.id.menu6: // here is a code of join
menu6 = true
break;
}
Upvotes: 2