Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

sap.m.ObjectListItem : Press event not working inside a Horizontal Layout

HI Guys,

I am trying to create a Left aligned vertical menu bar, similar to what we see on google playstore. So I am using an image + Object List Item control.

It looks well but the "press" event is not working on the ObjectListItem, though it works fine for the image. Here is what I am doing:

getMenuItems : function(){

  var oImg1 = new sap.ui.commons.Image({

  width : "65px",

  height : "57px",

  tooltip : "All Data Marts",

  src : "WebContent/img/AllMarts.png",

  press : function(oEvent){

            alert("Hello");   ----------------------> This works

       }

  });

  var oMenuItem1 = new sap.m.ObjectListItem({

       title : "All Marts",

       press : function(oEvent){

            alert("Hello"); ------------------------> This does not

       }

  });

  var oMenuLayout = new sap.ui.layout.HorizontalLayout();

  oMenuLayout.addContent(oImg1);

  oMenuLayout.addContent(oMenuItem1);

 

  var oView = this.getView();

  oView.oMenu.addContent(oMenuLayout);

}

Any thoughts how I can make it work? or any other ideas how I can create a menu like we see on playstore?

Tags:
Former Member
replied

You should set the ObjectListItem's "type" property to "Active" (the default value is undefined or Inactive)

Furthermore, you should not mix sap.ui.commons and sap.m libraries; better use sap.m.Image instead

But to get back to your topic, why go through all the hassle and create a horizontal layout with separate image and list items? Why not simply add an icon to your ObjectListItem, and add it to a List instead of directly into a view?

(And if you don't need all the extra goodies an ObjectListItem offers, why not simply use a StandardListItem instead?)

For instance:

  <List>

    <StandardListItem

      title="All Marts"

      icon="WebContent/img/AllMarts.png"

      press="handlePress" />

  </List>

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question