Basically I want only a menuitem icon for Edit to show up in the action bar if the current ParseUser
is viewing their own post.
I figure I could check if their viewing their own post simply by grabbing the current parse user like so (postedBy simply being a string from intent passed from listview activity):
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser.username == postedBy)
{
}
Problem is now how would I make it so only the a icon for Edit in the ActionBar shows up if this is the case, if not then they don't show up. (so others can't edit) Possibly in onOptionsItemSelected
? But that wouldn't make sense to me, what would make sense is having it where it's displayed which would be in XML?? Or possibly making two menu XMLS and calling one or the other depending if it's the current users post?
Well, you could have two menu xmls but that would be overkill (and harder to maintain). A much simpler solution would be to hide the menu option programmatically, i.e.
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main, menu);
// Show option depending on condition.
MenuItem item = menu.getItem(R.id.menu_item_edit_post);
item.setVisible(isUserPost());
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With