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
New Contributor
samup4web
Posts: 7
Registered: ‎02-01-2013
My Device: Various
My Carrier: Various

Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

[ Edited ]

Hi, 

I have a simple layout described in the diagram below:

 

I have used a simple VerticalFieldManager (container), with TableView and Another HorizontalFieldManager which holds the button. (I used setStatus(horizontalFM); to position the lower manager).

 

 

Problems:

-When I start the application, if I select the buttons first, if behaves as expected (fires the attached action). 

-However, whenever I interact with the tableview and then try to select/touch/click the button, it doesn't react to the actions.

-If I use scroll (direction buttons) to set the focus on the button and then select. it works fine too. 

-It seems the TableView traps the event first and takes over from buttons. 

 

Any idea on how to fix this?

 

Attempts:

- I reduced the height of the table so, it doesn't reach the status (horizontaiFieldManager). But it didn't work.

-Various focusable setting. (I have tried setting focusable on the button fields, the horizontalFieldManager and nothing seems to work.

 

Can anyone explain how to get a solution to this? 

 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Can you prepare a simple Screen with dummy data that demonstrates this problem.  Then we can test. 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

First of all, I guess you use setStatus and not setBanner for the lower manager. :smileyhappy:

Anyway, I remember some problem with ListField instead of TableView reported here. Back then it was confirmed as a bug and some ticket was opened. Since it was not mine, I don't remember all of the details, but you might find it if you search hard enough. Anyway, you might have hit a genuine BB problem, so you'll have to come with a workaround. For example, try limiting your VerticalFieldManager with TableView and adding the lower manager with the buttons to the same screen. You might also want to create your MainScreen with NO_VERTICAL_SCROLL and your VerticalFieldManager containing the TableView with VERTICAL_SCROLL.

 

Sorry for not being more helpful.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Contributor
samup4web
Posts: 7
Registered: ‎02-01-2013
My Device: Various
My Carrier: Various

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

[ Edited ]

@arkadyz, thanks for the correction. Yes, I meant setStatus.

 

I have tried limiting the height of the VerticalFieldManager. I have also tried using MainScreen with NO_VERTICAL_SCROLL and a VerticalFieldManager with VERTICAL_SCROLL with no success.

 

Anyway, I appreciate your contribution.

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Just to be sure I understand the problem, you have buttons at the bottom of a touch screen, and when you have interacted with the TableView which is being displayed in the upper portion of the screen, these Buttons become unresponsive (until you physcially move focus to them).   

 

In this case as well as having the VFMs involved, the TableView itself is potentially performing some Manager like scrolling and focus detection.  I suspect that this is where the problem is occurring and wanted to try various things out.  Unfortunately I am not a TableView user, so creating sample code is tricky for me.  Which is why I asked for a sample. 

 

If you can provide a sample I would be happy to look at it.

Please use plain text.
New Contributor
samup4web
Posts: 7
Registered: ‎02-01-2013
My Device: Various
My Carrier: Various

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner



public class TestyScreen extends MainScreen implements FieldChangeListener { private TableView theView; private RegionStyles tableRegionStyle; private TableModel theModel; ButtonField btn1; ButtonField btn2; /** * TODO define other parameters needed ... */ public TestyScreen() { //super(MainScreen.NO_VERTICAL_SCROLL); VerticalFieldManager vfm = new VerticalFieldManager(NO_VERTICAL_SCROLL); theModel = new TableModel(); theView = new TableView(theModel); TableController theController = new TableController(theModel, theView, TableController.ROW_FOCUS); theView.setController(theController); theController.setCommand(new CommandHandler(){ public void execute(ReadOnlyCommandMetadata metadata, Object context) { Dialog.alert("TableView clicked"); } }, null, null); tableRegionStyle = new RegionStyles(BorderFactory.createSimpleBorder( new XYEdges(1, 1,1, 1), Border.STYLE_SOLID), null, new XYEdges(2,0,2,0), null, RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_MIDDLE); // Initialize the DataTemplate. TableTemplate theTemplate = new TableTemplate(theView, 2, 3); theTemplate.createRegion(new XYRect(0, 0, 1, 2), tableRegionStyle); theTemplate.createRegion(new XYRect(1, 0, 1, 1), tableRegionStyle); theTemplate.createRegion(new XYRect(1, 1, 1, 1), tableRegionStyle); theTemplate.createRegion(new XYRect(2, 0, 1, 2), tableRegionStyle); theTemplate.setRowProperties(0, new TemplateRowProperties(27)); theTemplate.setRowProperties(1, new TemplateRowProperties(27)); theTemplate.setColumnProperties(0, new TemplateColumnProperties(62)); theTemplate.setColumnProperties(1,new TemplateColumnProperties(Display.getWidth() - 120)); theTemplate.setColumnProperties(2, new TemplateColumnProperties(60)); theTemplate.useFixedHeight(true); theView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.WHITE, Color.ORANGE, Color.ORANGE)); theView.setDataTemplate(theTemplate); //Load data into table loadData(theModel); //Add table to view vfm.add(theView); add(vfm); HorizontalFieldManager hfm = new HorizontalFieldManager(); btn1 = new ButtonField("btn1"); btn2 = new ButtonField("btn2"); hfm.add(btn1); hfm.add(btn2); btn1.setChangeListener(this); btn2.setChangeListener(this); setStatus(hfm); } public void fieldChanged(Field field, int context) { // TODO Auto-generated method stub if (field == btn1) { Dialog.alert("btn1 clicked!"); }else if (field == btn2) { Dialog.alert("btn2 clicked!"); } } public void loadData(TableModel theModel){ // Add the Strings to the table. theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); theModel.addRow(new String[] { "Text1", "Text1", "Text1", "Text1" }); } public class TableTemplate extends DataTemplate { public TableTemplate(DataView view, int rows, int columns) { super(view, rows, columns); } public Field[] getDataFields(int modelRowIndex) { TableModel theModel = (TableModel) getView().getModel(); Object[] data = (Object[]) theModel.getRow(modelRowIndex); Field[] theDataFields = new Field[data.length]; theDataFields[0] = new LabelField((String) data[0]); theDataFields[1] = new LabelField((String) data[1]); theDataFields[2] = new LabelField((String) data[2]); theDataFields[3] = new LabelField((String) data[3]); return theDataFields; } } }

 

Here is a sample code to reproduce the problem. 

-When I click on the table it shows a diaolog "table clicked", if I click on the button, it still shows "table clicked".

-If I however click on the button before touching the table, it show "button clicked"

-And if I scroll to give the button focus and then click, it also works as expected.

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Have replicated problem.  Thanks for the easy to use sample.

 

Looks like the TableView has decided that the bottom of the screen belongs to it....

 

Am investigating, but will be later before I reach any conclusions sorry. 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Interesting.

 

I think there is an issue with TableView.  In my playing round it seems that is does not like being added to a scrolling manager.  It seems it wants to manage its own scrolling.  But if it does that, then you do not get the scroll indicators. 

 

And it fails with array index exceptions when you scroll it places it doesn't want to do. 

 

Here is what I think is happening. 

 

To get the scroll indicators, you have to put it inside a normal VFM, as you did, and then add that to a screen which has a restricted height window.  Then the Screen delegateManager puts the scroll indicators in place.  However TableView thinks it has the whole height that it has grabbed from the VFM that it is contained in.  And so if it is has focus, and you press anywhere on the screen, it will try to see if that position is within its boundaries, using its extents rather than the actual extents bounded by the window it is being seen through.  And so as long as the status area is hiding a TableView row, the TableView will take the focus. 

 

I have been playing and it is relatively easy to get his working properly, in fact arkadyz pretty much suggested how to do it above. The easiest way to do it, is you define the MainScreen with:

super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.USE_ALL_HEIGHT);

Then don't use the VFM and just add the TableView to the screen.

 

But by doing this you loose the scrolling indicators. 

 

I must admit I have tried a few things to get them back without also causing this problem and failed. 

 

So at this stage, I am hoping that you can do without the scrolling indicators.

 

I'd also really appreciate arkadyz's input on this.  I hope he has a look at some stage. 

 

Hope this helps. 

Please use plain text.
New Contributor
samup4web
Posts: 7
Registered: ‎02-01-2013
My Device: Various
My Carrier: Various

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Well,  Thanks for the awesome information.

 

I settled for a work-around, which seem ok. I had to change the possition of my toolbar. Now, instead of having the toolbar (Buttons) below the table, I put the toolbar above the table. This solves the problem with focus for me. 

However, I just noticed that, when I scroll with touch, it the table scrolls fine, but, when I scroll with arrow keys, it doesn't scroll as expected. The focus goes out of view and the table doesn't scroll to the focus. 

 

Any idea on what might be wrong here?

 

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with touch event / focus /navigation Click. TableView with ButtonField on banner

Same problem perhaps.  The TableView thinks it has all the screen, so doesn't think it has to scroll to show the top items?

 

 

Please use plain text.