6

I'm trying to build a flashcard app with sencha touch 2. I have a label showing the question, which takes up the entire screen, I want it so that when the user taps on the label the answer shows. Does the label have a 'tap' event? It works when I use a button, but not when I use a label.

Another way around is if I can get the button to be transparent on top of a label. Any suggestions?

James Gu
  • 1,382
  • 4
  • 26
  • 39

3 Answers3

4

You can do this :

label.element.on({
    tap : function(e, t) { ... }
});

Hope this helps

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
2

one more way to bind the tap event to the 'label' control using sencha touch.

{
    xtype : 'label',
    html : 'my name is abc',
    listeners : 
    {
        element : 'element',
        tap : function(e, t) 
         {
           alert('1 pressed');
         }
    }
}
vipin katiyar
  • 3,437
  • 7
  • 24
  • 32
1

Ext.Label is not designed to have a tap event. However, you can still achieve it through the tap event on your label HTML element, for example:

label.getContentEl().on{'tap', handler_function,this}

But Sencha Touch does not provide tap event on Ext.Label, which is a child of Ext.Component, so when you try to use tap event on a label, it's not the best practice.

A better approach is to use Ext.Button with the following 2 configs:

{
  ui: 'plain',
  cls: 'btnCls',
}

and in your CSS, style its background to transparent.

Thiem Nguyen
  • 6,345
  • 7
  • 30
  • 50