2

I have made a Container compound by a TextArea and a CheckBox. In my app, I create so many of this "Containers" and add to each TextArea inside of them an ActionListener (implemented by the class). Something like this:

for(int i = 0 ; i<20;i++){
 MyContainer c = new MyContainer();
 TextArea t = c.getTextArea();
 t.addActionListener(this);
}

I want the TextArea to catch the event and if it is pressed put the CheckBox checked or unchecked. It works fine in non-touch devices and simulators but in the touch devices or emulators, the TextArea doesn't catch the event. I tried to put the TextAreaas the lead component of the Container but it doesn't works because Container doesn't have an addActionListener method.

Mun0n
  • 4,438
  • 4
  • 28
  • 46

2 Answers2

2

If I understand the question correctly you are trying to create a compound component assembled from multiple different components to act like a single component. In LWUIT/Codename One this is called a Lead Component, the attached post is mostly about the resource editor but the concepts apply to manual coding as well. Just set the "checkbox" as your lead and everything should work.

You can code this manually by deriving and overriding but you will there are small edge cases like the change of style states (focused/pressed state etc.)

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
0

It is better that you derive the TextArea class for the getTextArea() method. Then in this class implement the pointerReleased method : code the action performed in the normal way in it.

pheromix
  • 18,213
  • 29
  • 88
  • 158