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

Adobe AIR Development

Reply
Contributor
Posts: 22
Registered: ‎01-28-2011
My Device: Not Specified
Accepted Solution

List always goes back to top item

I'm using a QNX List component with a CellRenderer and when I have more items than what can fit on the list area, I scroll down but the list bounces back to the top item. Below is the code I use to create the list:

 

            myList = new List();
            
            myList.y = 30;
            myList.rowHeight = 88;                    
            myList.size=90;                            
            myList.sizeUnit = SizeUnit.PERCENT;
            myList.scrollable = true;
            myList.opaqueBackground = 0x333333;        
            myList.scrollBarColor = 0xCCCCCC;        
            
            myCellRenderer = new MyCellRenderer();
            myList.setSkin(MyCellRenderer);    
            myList.dataProvider = new DataProvider( routine.getArray() );
        
            myList.selectionMode = ListSelectionMode.SINGLE;
            myList.allowDeselect = false;
            myList.selectedIndex = 0;        
            
            listContainer.addChild(myList);

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: List always goes back to top item

[ Edited ]

I'm going to guess it has to do with "allocating" your renderer.  You just have to set it to your class definition.

 

myList.setSkin( MyCellRenderer );

 

If it sill continues to reset, please re-post.

 

[EDIT].  Re-reading, maybe you are doing this. Hence the danger to have an attribute so similar to the class definition.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: List always goes back to top item

hey,

 

thats strange. i havent tested it yet but, is this contained any another another object? if so does that object have an event listener that might be interfering with the MouseDown of the list event?

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: List always goes back to top item

So, question; is the sole purpose of a "cell renderer" to just display a drop down with your own styling?? Or what? I've seen the term but never really wondered what exactly it is...
CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: List always goes back to top item

hey nick,


The purprose of the Cell Renderer class is to "skin" a list or a dropdown menu. it can be applied to other objects such as the pickerlist. the look and feel of everything is done via some kind of skinning component. like the label buttons and what not. so the skin in the case of lists and dropdowns is the Cell Renderer or the Alternating Cell Renderer class.

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 22
Registered: ‎01-28-2011
My Device: Not Specified

Re: List always goes back to top item

[ Edited ]

@jtegen: setSkin must be passed a class name. It is a class factory of sorts. My code was misleading and I need to delete the previous instantiation line (at one point I thought it required an instance too):

 

            //myCellRenderer = new MyCellRenderer();   NOT REQUIRED
            myList.setSkin(MyCellRenderer);   

 

@JRab: the list is in a container and that container is part of a class the extends Sprite.

 

The list appears to work and I have buttons, a picker, and image on each row and they show up ok and they sort of scroll. I scoll down and I see some of the items that are below my list area but then the list just bounces back up to the top.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: List always goes back to top item

hey chillybin,

 

this may sound a little extreme but try to remove the custom skin of your list and see if that changes anything. i doubt it will but some users have experienced weird things when it came to applying a renderer. so try that out and see what happens. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 22
Registered: ‎01-28-2011
My Device: Not Specified

Re: List always goes back to top item

I took out the CellRenderer and same problem. I created a test program that has the same problem. Do I need to refresh the list somehow? When I ran the program and press the button, a new item is pushed onto the array and it shows up immediately on the list but I can't scroll there without the list popping back up. I can see it momentarily on the bottom. The original items added in the contructor all scroll fine.

 

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;    
    import qnx.ui.buttons.LabelButton;
    import qnx.ui.core.Container;
    import qnx.ui.core.ContainerFlow;
    import qnx.ui.core.SizeMode;
    import qnx.ui.core.SizeUnit;
    import qnx.ui.data.DataProvider;
    import qnx.ui.listClasses.List;
    import qnx.ui.listClasses.ListSelectionMode;
    import qnx.ui.listClasses.ScrollPane;
    
    public class MobileList extends Sprite
    {
        private var mainContainer:Container;
        private var btn:LabelButton;
        private var anArr:Array;
        private var taskTimerList:List;
        
        public function MobileList()
        {
            super();            
            addEventListener(Event.ADDED_TO_STAGE,handleAddedToStage);
            mainContainer = new Container();
            mainContainer.margins = Vector.<Number>([10,10,10,10]);    
            mainContainer.flow = ContainerFlow.VERTICAL;
            mainContainer.debugColor = 0x3333FF;    
            this.addChild(mainContainer);
            
            btn = new LabelButton()
            btn.label = "Add Item";
            btn.addEventListener(MouseEvent.CLICK, onClick);
            mainContainer.addChild(btn);
            
            taskTimerList = new List();
            taskTimerList.rowHeight = 25;                
            taskTimerList.size=100;                            
            taskTimerList.sizeUnit = SizeUnit.PERCENT;
            taskTimerList.scrollable = true;
            
            anArr = new Array();
            anArr.push({ label:"one" });
            anArr.push({ label:"two" });
            anArr.push({ label:"three" });
            anArr.push({ label:"four" });
            anArr.push({ label:"five" });
            anArr.push({ label:"six" });
            anArr.push({ label:"seven" });
            anArr.push({ label:"eight" });
            
            taskTimerList.dataProvider = new DataProvider(anArr);
            
            mainContainer.addChild(taskTimerList);
        }
        private function onClick(e:MouseEvent):void
        {
            anArr.push({ label: anArr.length.toString() });
        }
        
        private function handleAddedToStage(e:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE,handleAddedToStage);
            stage.addEventListener( Event.RESIZE, onResize );
            onResize(new Event(Event.RESIZE));
        }
        private function onResize(event:Event):void
        {
            mainContainer.setSize(stage.stageWidth, stage.stageHeight/2);
            
        }
    }
}

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: List always goes back to top item

hey chillybin,

 

im glad you posted your full code, finally see it. you are adding to the list improperly. the list class has a method called addItem() that you should use. so although currently you are adding to the list, the list doesnt know that and cant update its scrolling. so do the follwing:

 

change this:

 

 

		private function onClick(e:MouseEvent):void
		{
			anArr.push({ label: anArr.length.toString() });

		}

 

 

to this:

 

 

		private function onClick(e:MouseEvent):void
{
taskTimerList.addItem({label: "New Item"});
}

 

that should clear things up. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Contributor
Posts: 22
Registered: ‎01-28-2011
My Device: Not Specified

Re: List always goes back to top item

Thanks JRab - that worked!