I have created a VerticalFieldmanager optFieldManager
in which i have added some CustomButtons
Then i want to invoke the button’s functionality using touch event method
i tried this using the TouchEvent() method
For this i do fetch the index of optFieldManager which gives the index value as 0
which confirms that the field is present
But then i again ask for the field inside the manager which returns -1 value which means there is no field added to Manager … which isn’t true
I debugged the code and found that the clicked postions are correctly returned
int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1));
but the index1 value comes as -1 which is wrong
what’s the problem
I have added the snippet of code below
protected boolean touchEvent(TouchEvent message) {
switch(message.getEvent())
{
case TouchEvent.CLICK:
{
int index=getFieldAtLocation(message.getX(1), message.getY(1));
//int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1));
if(index!=-1)
{
Field field=getField(index);
if(field.equals(optionVertFldMgr))
{
int index1=optionVertFldMgr.getFieldAtLocation(message.getX(1), message.getY(1));
System.out.println("HELOOOOOOO"+((VerticalFieldManager) field).getFieldAtLocation(message.getX(1), message.getY(1)));
//int index1=optionVertFldMgr.getFieldWithFocusIndex();
if(index1>-1)
{
Field fld=optionVertFldMgr.getField(index1);
if(fld.equals(m_agendaBtn))
{
fld.setFocus();
return true;
}else if(fld.equals(m_eventFeedBackBtn))
{
fld.setFocus();
UiApplication.getUiApplication().pushScreen(new EventFeedbackScreen());
return true;
}
}
}
}
}
}
return false;
}
You can always override Field.navigationClick on each button, or even override once in the screen and manage from there all events from every field:
This approach works both for touchscreens and trackpad.