Extending MenuItem in Android Java

Viewed 207

I'm a newbie Android Developer and my goal is to extend MenuItem in my custom AppCategory class. I've understood that I need to implement it rather than extend it because MenuItem in an interface, but unfortunately it forces me to implement all it methods by myself. My question in how to find out most elegant solution?

public class AppCategory extends MenuItem {
    private String name;
    private String displayName;
    private String iconFile;
    private MenuItem navItem;

    private List<App> appsList;

    public AppCategory(String name, String displayName, String iconFile, List<App> appsList, Menu menu) {
        this.name = name;
        this.displayName = displayName;
        this.iconFile = iconFile;
        this.appsList = appsList;

        this.navItem = menu.add(this.displayName);
        int iconResNum = getResId(this.iconFile, R.drawable.class);
        navItem.setCheckable(true);

        // Icon image was found
        if (iconResNum != -1) {
            navItem.setIcon(iconResNum);
        }

        this.navItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                return true;
            }
        });
    }

    public String getName() { return this.name; }
    public String getDisplayName() { return this.displayName; }
    public String getIconFile() { return this.iconFile; }
    public List<App> getAppsList() { return this.appsList; }
}
0 Answers
Related