Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
kellogs
Posts: 14
Registered: ‎06-19-2011
My Device: simulator Torch 9800
Accepted Solution

button would not accept focus if touched

Hello,

 

Below is my problem screen: untitled.PNG

 

I can get to the 'Run' button with the trackpad and then click it / touch it and it works, but I would like it to acquaire focus and get clicked just by touching it even if it it does not currently have focus. Any way for doing this ?

 

My code constructor code:

 

super(Screen.NO_VERTICAL_SCROLL);
        
        try 
        {
        	_odcSettings = new Settings();
        	
        	// Manager to lay out checkboxes
        	ManagerSets vfm = new ManagerSets(USE_ALL_WIDTH);
        	this.add(vfm);
        	
        	_iciNumbersField = new LabelField("I.C.I. Numbers: ");
        	_iciNumbers011Field = new CheckboxField("011", _odcSettings.getPrefix1().length() > 0);
        	_iciNumbersP1Field = new CheckboxField("+1", _odcSettings.getPrefix2().length() > 0);
        	        	
        	_autorunField = new LabelField("Autorun: ");
        	_autorunGroup = new RadioButtonGroup();
        	_autorunFieldOn = new RadioButtonField("Yes", _autorunGroup, _odcSettings.isAutostart());
        	_autorunFieldOff = new RadioButtonField("No", _autorunGroup, !_odcSettings.isAutostart());
        	
        	_autosendField = new LabelField("Autosend password: ");
        	_autosendGroup = new RadioButtonGroup();
        	_autosendFieldOn = new RadioButtonField("Yes", _autosendGroup, _odcSettings.isSendDtmf());
        	_autosendFieldOff = new RadioButtonField("No", _autosendGroup, !_odcSettings.isSendDtmf());
        	
        	_pwdField = new LabelField("Password: ");
        	_pwdTextField = new PasswordEditField("", _odcSettings.getDtmf(), 16, PasswordEditField.FILTER_NUMERIC);
        	
        	_runField = new ButtonField("Run", Field.FIELD_HCENTER);
        	_runField.setChangeListener(this);
        	
           	vfm.add(_iciNumbersField);
        	vfm.add(_iciNumbers011Field);
        	vfm.add(_iciNumbersP1Field);
        	vfm.add(_autorunField);
        	vfm.add(_autorunFieldOn);
        	vfm.add(_autorunFieldOff);
        	vfm.add(_autosendField);
        	vfm.add(_autosendFieldOn);
        	vfm.add(_autosendFieldOff);
        	vfm.add(_pwdField);
        	vfm.add(_pwdTextField);
        	vfm.add(_runField);
        	
        }  catch (Exception e) {

        	e.printStackTrace();
        }

 Thanks!

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: button would not accept focus if touched

Hi,

 

Try with overriding touchevent. Something like:

 

protected boolean touchEvent(TouchEvent event) 
{
    boolean returnValue = super.touchEvent(event);
    switch(event.getEvent()) 
    {
        case TouchEvent.DOWN:
         int index = getFieldAtLocation(event.getX(1), event.getY(1));
         if (index == -1) return returnValue;
         return super.touchEvent(event); 
        case TouchEvent.MOVE:
         return true;
        case TouchEvent.UP:
         return true;
        case TouchEvent.CLICK:
         return true;
     }
     return returnValue;
}

 Regards

Bikas

Please use plain text.
Contributor
kellogs
Posts: 14
Registered: ‎06-19-2011
My Device: simulator Torch 9800

Re: button would not accept focus if touched

good hint.

 

This has worked for me:

 

	protected boolean touchEvent(TouchEvent event) 
{
try
{
int index = vfm.getFieldAtLocation(event.getX(1), event.getY(1));

switch(event.getEvent())
{
case TouchEvent.CLICK:
if (vfm.getField(index) == _runField)
{
_runField.setFocus();
_runField.forceClick();
}
return true;
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return super.touchEvent(event);
}

 

 

 

Please use plain text.