public View getView(int position, View convertView, ViewGroup parent) { View rowView = convertView; ViewHolder viewHolder; if (rowView == null) { LayoutInflater inflater = context.getLayoutInflater(); rowView = inflater.inflate(resourceId, null); viewHolder = new ViewHolder(); viewHolder.labelTv = (TextView) rowView.findViewById(R.id.sliding_menu_label); rowView.setTag(viewHolder); } else { viewHolder = (ViewHolder) rowView.getTag(); } MenuItem item = list.get(position); int iconResId = item.getIconResId(); if (iconResId != 0) { viewHolder.labelTv.setCompoundDrawablesWithIntrinsicBounds( context.getResources().getDrawable(iconResId), null, null, null); } viewHolder.labelTv.setText(item.getLabel()); return rowView; }
public MenuItemFragment(MenuItem menuItem) { super("menuItemFragment", "MENU_ITEM_FRAGMENT", MenuPanel.this); setRenderBodyOnly(true); // add the menu's label (hyperlinked if a link is provided) if (menuItem.getLink() != null) { if (menuItem.getImage() != null) { if (menuItem.getLabel() != null) { add( new LinkImageTextFragment( menuItem.getLink(), menuItem.getImage(), menuItem.getLabel())); } else { add(new LinkImageFragment(menuItem.getLink(), menuItem.getImage())); } } else { add(new LinkFragment(menuItem.getLink(), menuItem.getLabel())); } } else { if (menuItem.getImage() != null) { if (menuItem.getLabel() == null) { add(new ImageFragment(menuItem.getImage())); } } else { add(new TextFragment(menuItem.getLabel())); } } WebMarkupContainer menuItemList = new WebMarkupContainer("menuItemList"); add(menuItemList); // hide the <ul> tag if there are no submenus menuItemList.setVisible(menuItem.getChildren().size() > 0); /* // add a down or right arrow icon if there are children if (menuItem.getChildren().size() > 0) { menuItem.getLabel().add(MENU_HAS_SUBMENU_APPENDER); } */ // add the submenus menuItemList.add(new SubMenuListView("menuItemLinks", menuItem.getChildren())); }