如何处理ButtonField字段和放大器; BitmapField点击黑莓风暴(触摸)事件? [英] How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

查看:191
本文介绍了如何处理ButtonField字段和放大器; BitmapField点击黑莓风暴(触摸)事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ButtonField字段&安培;如..一个BitmapField

I have created a ButtonField & a BitmapField like..

  public class MyCanvas extends MainScreen implements FieldChangeListener
  {
    HorizontalFieldManager hfm;
    private Bitmap startBitmap;
    private BitmapField startBitmapField;
    private ButtonField okButton;

   MyCanvas()
   {
     hfm = new HorizontalFIeldManager();
     startBitmap = Bitmap.getBitmapResource("start.png"); 
     startBitmapField = new BitmapField(startBitmap);
     startBitmapField.setChangeListener(this); 
     hfm.add(startBitmapField);

     okButton = new ButtonField("Ok", ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY); 
     okButton.setChangeListener(this);
     hfm.add(okButton);
   }

   public void fieldChanged(Field field, int context)
   {
    if(field == startBitmapField)
    {
        System.out.println("Touched START...");
    }
    else if(field == okButton)
    {
        System.out.println("Touched Ok...");
    }
   }
}

但ButtonField字段或BitmapField点击没有在黑莓4.7模拟器发生。

But the ButtonField or BitmapField click is not happening in Blackberry 4.7 simulator.

我想建立它的黑莓风暴所以我米使用黑莓4.7

I want to build it for Blackberry Storm so I m using Blackberry 4.7

如何处理点击/触摸事件ButtonField字段和放大器; BitmapField黑莓风暴?

How to handle click/touch events for ButtonField & BitmapField for Blackberry Storm?

我为创建ButtonField字段和放大器; BitmapFields为

I m creating the ButtonField & BitmapFields as

okButtonField = new ButtonField("Ok", BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE);

startBitmapField = new BitmapField(startBitmap, BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE);

及其与工作..

Its working with..

protected boolean touchEvent(TouchEvent event)
{
  switch( event.getEvent()  ) 
  {
    case TouchEvent.DOWN:  ........
            return true;
    case TouchEvent.MOVE: .......
                            return true;
    case TouchEvent.UP: ........ 
                            return true;   

    case TouchEvent.CLICK:
      if(deleteButton.isFocus())
      {            
        System.out.println("Touched DEL ..........");
      }
      else if(okButton.isFocus())
      {            
        System.out.println("Touched OK ..........");
      }   
      else if(startBitmapField.isFocus())
      {            
        System.out.println("Touched START ..........");
      }         
    return true;
  }
  return false;
 }

但每次同一个按钮调用它是有焦点。

but everytime the same button is invoked which is having focus.

意味着,如果确定按钮是其重点则即使ü点击删除按钮确定按钮将被调用。

Means if "Ok" button is having focus then even though u clicked on "Delete" button "Ok" button is called.

那么如何改变焦点按钮单击?指取单击ButtonField字段或BitmapField,应该获得焦点?

So how to change the focus on Button Click? means whichever ButtonField or BitmapField is clicked, should get the focus?

在那里检查button.isClicked()之类button.isFocus()的任何方法?

is there any method to check "button.isClicked() like button.isFocus() " ?

推荐答案



首先,不要忘了HFM添加到屏幕;)

其实按钮单击工作正常。

现在,为了使位图单击工程以及,实施您的BitmapField保护布尔的TouchEvent(的TouchEvent消息)。这将是更好地创建扩展类:


First of all, don't forget to add hfm to screen ;)
Actually button click works fine.
Now, to make bitmap click works as well, implement protected boolean touchEvent(TouchEvent message) for your BitmapField. It will be better to create extended class:

class MyCanvas extends MainScreen implements FieldChangeListener {
    HorizontalFieldManager hfm;
    private Bitmap startBitmap;
    private BitmapField startBitmapField;
    private ButtonField okButton;
    private ButtonField cancelButton;

    MyCanvas() {
    	hfm = new HorizontalFieldManager();
    	add(hfm);

    	startBitmap = Bitmap.getBitmapResource("start.png");
    	startBitmapField = new TouchBitmapField(startBitmap);
    	startBitmapField.setChangeListener(this);
    	hfm.add(startBitmapField);

    	okButton = new ButtonField("Ok", ButtonField.CONSUME_CLICK
    			| ButtonField.NEVER_DIRTY);
    	okButton.setChangeListener(this);
    	hfm.add(okButton);

    	cancelButton = new ButtonField("Cancel", ButtonField.CONSUME_CLICK
    			| ButtonField.NEVER_DIRTY);
    	cancelButton.setChangeListener(this);
    	hfm.add(cancelButton);
    }

    public void fieldChanged(Field field, int context) {
    	if (field == startBitmapField) {
    		System.out.println("Touched START...");
    	} else if (field == okButton) {
    		System.out.println("Touched Ok...");
    	} else if (field == cancelButton) {
    		System.out.println("Touched Cancel...");
    	}
    }
}

class TouchBitmapField extends BitmapField {
    public TouchBitmapField(Bitmap startBitmap) {
    	super(startBitmap);
    }

    protected boolean touchEvent(TouchEvent message) {
    	if (TouchEvent.CLICK == message.getEvent()) {
    		FieldChangeListener listener = getChangeListener();
    		if (null != listener)
    			listener.fieldChanged(this, 1);
    	}
    	return super.touchEvent(message);
    }
}

这篇关于如何处理ButtonField字段和放大器; BitmapField点击黑莓风暴(触摸)事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆