I have a ListView in my activity. I also have a menu and there is a menuitem for saving the list. I want to make it behave like the pseudocode below:
if (myList.size() > 0) {
menuitem.setVisible(true);
} else {
menuitem.setVisible(false);
}
I want the "save" menuitem to show only when there is at least one item in the listview. I have a custom ArrayAdapter implementation also, can this action be made from there? Or is there any kind of listener I could use?
Any help is appreciated!
EDIT:
JDev answer is the solution. I changed only one thing: I moved the list size checking to notifyDataSetChanged() method inside my custom ArrayAdapter and now it works!
/**
* {@inheritDoc}
*/
@Override
public void notifyDataSetChanged() {
// Hide/show 'save' menuitem
if (mListItems.size() > 0) {
mListener.setMenuItemVisible(true);
} else {
mListener.setMenuItemVisible(false);
}
super.notifyDataSetChanged();
}