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
Posts: 10
Registered: ‎10-30-2012
My Device: Bold 9900
My Carrier: Vodafone

Listfield Issue

Hi all,

 

I'm developing an app in OS 5.0 which contains a table showing results and for this I've used what appears a quite popular bit of code which implements a Listfield and a TableRowManager. Each row is wider than the screen width and all the data displays and ir generally functions well ... except for one quite annoying niggle.

 

If I scroll to the right, either via swipe gesture or using the nav button, the screen scrolls as expected, but scroll down to the next row and the focus returns to the far left of that row. What I need to happen is the position within the table is retained. In the calling screen (to which this Listfield is added), the Listfield is added inside a VerticalFieldManager which is defined as follows:

 

new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR | VerticalFieldManager.NO_VERTICAL_SCROLL | VerticalFieldManager.NO_VERTICAL_SCROLLBAR | VerticalFieldManager.NO_SCROLL_RESET)
		{
			   protected void sublayout( int maxWidth, int maxHeight )
			   {
			       //set your width
			       int width;
			       if (type.equals("Actual"))
			    	   width = widthNum + widthProduct + widthQuantity + widthUOM + widthBooking + widthDate + widthWeighbridge + widthContract + widthMovement + widthCarrier + widthVehicleReg;
			       else
			    	   width = widthNum + widthProduct + widthQuantity + widthUOM + widthFixing + widthFrom + widthTo + widthContract + widthMovement + widthCarrier + widthEmpty;
			       //set your height
			       int height;
			       if (type.equals("Planned"))
			    	   height = (vectorPlannedMovements.size() + 1) * subHeight;
			       else
			    	   height = (vectorActualMovements.size() + 1) * subHeight;
			 
			       super.sublayout( width, height);
			       setExtent( width, height);
			   }
		};

 

This is then added inside a HorizontalFieldManager which is defined as follows and contains the headers which are contained within a TableLayoutManager:

 

HorizontalFieldManager hfmTable = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL | HorizontalFieldManager.HORIZONTAL_SCROLLBAR | HorizontalFieldManager.NO_SCROLL_RESET);

I felt that the NO_SCROLL_RESET would prevent this issue but it hasn't.

 

I'm a bit of a novice wrt BB coding, but I'm pretty sure I need to override a method of some sort but which one eludes me. I've searched over and over again on here and on other forums but to no avail. My hope is someone out there has experienced the same issue and has a solution.

 

Kind regards,

 

Mark

 

Developer
Posts: 16,932
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Listfield Issue

welcome to the support forums.

i think it is a focus issue, when you swipe to the side the focus stays on the first list, and if you scroll now the focused field goes into view again.
maybe you can move the focus with your swipe gesture?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 10
Registered: ‎10-30-2012
My Device: Bold 9900
My Carrier: Vodafone

Re: Listfield Issue

Many thanks for the welcome and also for the swift reply Smiley Happy

The app is designed so it will also function on older devices which do not have swipe gestures and the same behaviour is seen on those when using the nav button which requires me to find a solution which will handle both.

What is the purpose of NO_SCROLL_RESET and any ideas as to why it hasn't served its purpose (or maybe it has and I'm expecting too much of this parameter)?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Listfield Issue

Sorry just dropped in very quickly, not read the question completely, and may have missed something.

 

One of the issues noted typically with HFM but also applies to VFM is that when you scroll off these, and scroll back onto them, focus is returned to the first or last Field in the Manager depending on the direction of the scroll. 

 

Most people comment on this with HFM.  They have a number of buttons in a carousel for example, they select one of these, then scroll down, when they scroll back up, focus does not automatically return to the recently pressed button, it returns to the last Field in the HFM.

 

The only way round this, as far as I know, is to maintain in the HFM, an indication of the selected button, and in the Managers 'onFocus(int direction)' actually swap focus to the selected button.

 

I see no reason why the same issue will not happen with VerticalFieldManagers when you swipe left and right. 

 

So perhaps the solution here is to maintain some indication of which Field was selected and return focus there in 'onFocus(..)'.

 

Hope this helps.

Contributor
Posts: 10
Registered: ‎10-30-2012
My Device: Bold 9900
My Carrier: Vodafone

Re: Listfield Issue

Many thanks for the response.

 

The only field I have to focus on is the listfield which spans the screen and beyond, and this may be why focus is being returned to the start of each row. I personally feel that problem is to do with the VFM and that I need to override some method to prevent it from scrolling back to the start of the row, I'm sure it is this which is resetting. I just don't know which method to override and what with.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Listfield Issue

OK I have reviewed the question in more detail now and my comment was not relevant. 

 

I am not sure of which Managers are added to what,  Given that the screen is the outer level Manager, can you tell us which Managers are added to which container.  For example is the VFM you share with us added to the screen or to the HFM?

 

You say that the Table is displayed using a ListField.  I don't think a ListField is a great thing to display a whole table but might be useful to display one column.  Is this what you have done? 

 

Or have you in fact used TableLayoutManager for everything?

 

If you could clarify exactly what Fields are in what places and where these are in the 'container' hierarchy that would help.

 

Thanks. 

Contributor
Posts: 10
Registered: ‎10-30-2012
My Device: Bold 9900
My Carrier: Vodafone

Re: Listfield Issue

Ok, this is what I have (I tried to insert the image but it wouldn't have it so have provided a link instead)

 

 BB Layout Image

 

Each row has 12 fields, the row is constructed in a TableRowManager (override of sublayout), populated from a vector. I want the user to be able to scroll around but there's no need for individual cells to be highlighted. In essence, you could argue that it is displaying one column.

 

The Listfield does the job for what I need, it just has a rather ugly side-effect which I can't seem to get around.

 

If you need any further info, let me know Smiley Happy

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Listfield Issue

OK, got that.  Added here as an attachment for others to find easier. 

 

You appear to be using ListField in a very complicated way if you are actually formatting each ListField Row using TableLayoutManager.  It works, but is not for the faint hearted.

 

But even when you sue this approach, the whole row gets focus, not just the left or right.  You can if you try very hard, use ListField to simulate focus movement across the row, but that is quite complicated, I don't know of any situation where this has been done.  So if you are doing this, kudos to you!  But my point is that in my experience, using ListField with a width that is wider than the screen involves

a) Some clever offsetting with the x position in the drawListRow

b) Does not cause a horizontal scroll when the focus moves down a row. 

 

So my suspicion is that you are not using ListField at all, I think you are actually using TableLayoutManager for each row.  You can test this relatively easily,  put a break point in the navigationMovement code in TableLayoutManager.  Then move around what should be your ListField.  Becuase you use TableLayoutManager to provide formatting only, this method shouldn't be involved.  is it?

Contributor
Posts: 10
Registered: ‎10-30-2012
My Device: Bold 9900
My Carrier: Vodafone

Re: Listfield Issue

The TableLayoutManager is used purely to display the column headers, it doesn't venture anywhere near the rows. In fact, this code is resident in the MainScreen activity. The rows are handled by a TableRowManager inside the Listfield
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Listfield Issue

Apologies. 

 

OK, I think I have figured out how you are doing this, for some reason I was fixated on a different solution...  I think that is because of this comment:

"the focus returns to the far left of that row"

I actually think what happens is the scroll returns to the left hand side.  With a ListField the focus is the entire row

 

Tell me, in the drawListRow method call, what is the width that is past in?  Is it the width of the screen or the full width of the table?

 

As an experiment, override navigationMovement in your vfmTable and hfmTable.  In that code, just display the current Horizontal and Vertical scroll position (this.getHorizontalScroll(), ...), before and after a call to super.navigationMovement().  Debug this while moving your trackpad around. I think this might be revealing regarding what is changing your scroll position.

 

The code will look something like:

 

protected void navigationMovement(...) {

System.out,println("Current H: " + this.getHorizontalScroll() + ",V:" + this.getVerticalScroll());

super....

System.out,println("Current H: " + this.getHorizontalScroll() + ",V:" + this.getVerticalScroll());

}