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
New Developer
adessugbaa
Posts: 8
Registered: ‎01-13-2011
My Device: Not Specified
Accepted Solution

Adding items to QNX list without scrolling

Is it possible to refresh items in a qnx list without scrolling the list back to the 1st item?

 

I have a qnx list that gets its list items from a feed, and if the list item has been scrolled, each time I refresh the dataprovider, it automatically reloads the list with the 1st item on display.

 

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Adding items to QNX list without scrolling

hey adessugbaa,

 

how are you refreshing the list? when i add an item to the list it keeps it in the current position. a sample of the code you are using would be great too. thanks!

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
Please use plain text.
New Developer
adessugbaa
Posts: 8
Registered: ‎01-13-2011
My Device: Not Specified

Re: Adding items to QNX list without scrolling

 

arrMonth = new Array();
for each (var dt:StatusData in event.responseArray)
{
    var obj:Object = new Object();
    obj.name = dt.user.screenName;
    obj.time = TweetUtil.returnTweetAge(dt.createdAt);
    obj.tweettext = dt.text;
    obj.thumb = dt.user.profileImageUrl;
    obj.lon = dt.geoLong;
    obj.lat = dt.geoLat;
    obj.location = dt.user.location;
    
    //log(dt.id.toString());
    //log(dt.text);
    //log(dt.user.name);
    //log(dt.user.profileImageUrl);
    arrMonth.push({label: obj.name, data: obj});
    log(obj.lon);
}
//log("List Content W: "+listContent.width+" H: "+listContent.height);

var firstindex:int = 0;
if (refresh)
{
    if (list != null)
        list.dataProvider = new DataProvider(arrMonth);                    
}
else
{
    //if (list != null)
    //    listContent.removeChild(list);
    list = new List();
    list.setSkin(TwitterRendererSkin);
    list.x=1;
    list.y=1;
    list.width = listContent.width-2;
    list.height = listContent.height-2;
    list.rowHeight = 150;
    list.dataProvider = new DataProvider(arrMonth);
    list.selectionMode = ListSelectionMode.NONE;
    list.allowDeselect = false;
    list.selectedIndex = firstindex;
    list.addEventListener(ListEvent.ITEM_CLICKED, listSelected);
    list.addEventListener(ScrollEvent.SCROLL_END, getPos);
    listContent.addChild(list);
}

In the code snippet above, i check if the data is being refreshed, and set the data provider.

 

What i want to do is selectively add content that is not currently in the list (this will be at the beginning since it is twitter feeds), and maintain the user's position in the list.

 

Thanks.

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Adding items to QNX list without scrolling

hm sounds pretty interesting. what i would do is find something to sets one set of data apart from the others and makes each tweet unique. there is probably an ID from the API or something. then id have a seperate array keeping track of all the ID's within ur current list. from there everytime u "referesh" you can check if the IDs in the new list you got are different than your current array of IDs. if they are seperately add each individual tweet from the new incoming list using the addItem() method instead of resetting your entire dataprovider. hope that helps some. 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
Please use plain text.
New Developer
adessugbaa
Posts: 8
Registered: ‎01-13-2011
My Device: Not Specified

Re: Adding items to QNX list without scrolling

Thanks...

Please use plain text.
New Developer
adessugbaa
Posts: 8
Registered: ‎01-13-2011
My Device: Not Specified

Re: Adding items to QNX list without scrolling

I have logic that checks for the existence of tweet rows. I only add new rows, but i still have the list scrolling depending on the number of rows added.

 

Because of the chronological nature of tweets, i have to add tweets to the top of the list, and not the bottom.

 

 

if (refresh)
{		
}
else
{
	list = new List();
	list.setSkin(TwitterRendererSkin);
	list.x=1;
	list.y=1;
	list.width = listContent.width-2;
	list.height = listContent.height-2;
	list.rowHeight = 150;
	list.dataProvider = dp;
	list.selectionMode = ListSelectionMode.NONE;
	list.allowDeselect = false;
	list.selectedIndex = firstindex;
	list.addEventListener(ListEvent.ITEM_CLICKED, listSelected);
	list.addEventListener(ScrollEvent.SCROLL_END, getPos);
	listContent.addChild(list);
}

var arrMonth = new Array();
var i:int = 0;
var respSize:int = event.responseArray.length;

for each (var dt:StatusData in event.responseArray)
//for (var i:int = respSize - 1; i >= 0; i--)
{
	log("reloading tweets");
	//var dt:StatusData = event.responseArray[i];
	var obj:Object = new Object();
	obj.id = dt.id;
	obj.name = dt.user.screenName;
	obj.time = TweetUtil.returnTweetAge(dt.createdAt);
	obj.tweettext = dt.text;
	obj.thumb = dt.user.profileImageUrl;
	obj.lon = dt.geoLong;
	obj.lat = dt.geoLat;
	obj.location = dt.user.location;
	
	//log(dt.id.toString());
	//log(dt.text);
	//log(dt.user.name);
	//log(dt.user.profileImageUrl);
	if (!containsTweet(dt.id, dp.data))
	{
		if (refresh)
		{
			dp.addItemAt({label: obj.name, data: obj}, i);
			i++;
		}
		else
			dp.addItem({label: obj.name, data: obj});
		//list.dataProvider.data.push({label: obj.name, data: obj});
		//i++;
	}
		//arrMonth.push({label: obj.name, data: obj});
	//log(obj.lon);
}

 

 

Can you please give me a code snippet that shows you adding rows to a list?

 

Thanks.

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Adding items to QNX list without scrolling

hey,

 

here is a simple code showing you the same add you are performing (addItemAt method):

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.data.DataProvider;
	import qnx.ui.listClasses.List;
	
	
	[SWF(width="1024",height="600",backgroundColor="#E8E8E8",frameRate="30")]
	public class ListTests extends Sprite
	{
		private var myList:List;
		private var myDataProvider:DataProvider;
		private var myArray:Array;
		private var myBtn:LabelButton;
		
		public function ListTests()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			myList = new List();
			myArray = new Array();
			
			myArray.push({label: "Thomas Luddington"});
			myArray.push({label: "Master Maruyn"});
			myArray.push({label: "Master Gardyner"});
			myArray.push({label: "Captain Vaughan"});
			myArray.push({label: "Master Kendall"});
			myArray.push({label: "Master Prideox"});
			myArray.push({label: "Robert Holecroft"});
			myArray.push({label: "Rise Courtenay"});
			myArray.push({label: "Master Hugh Rogers"});
			myArray.push({label: "Thomas Foxe"});
			myArray.push({label: "Edward Nugen"});
			myArray.push({label: "Darby Glande"});
			myArray.push({label: "Edward Kelle"});
			myArray.push({label: "Iohn Gostigo"});
			myArray.push({label: "Erasmus Clefs"});
			myArray.push({label: "Edward Ketcheman"});
			myArray.push({label: "Iohn Linsey"});
			myArray.push({label: "Thomas Rottenbury"});
			myArray.push({label: "Roger Deane"});
			myArray.push({label: "Iohn Harris"});
			
			myDataProvider = new DataProvider(myArray);
			
			myList.dataProvider = myDataProvider;
			
			myList.setPosition(10,10);
			myList.setSize(300,300);
			
			addChild(myList);
			
			myBtn = new LabelButton();
			myBtn.label = "Add John Doe At Position 5";
			myBtn.setSize(250, 50);
			myBtn.setPosition(360, 70);
			
			myBtn.addEventListener(MouseEvent.CLICK, addPerson);
			
			addChild(myBtn);
			
		}
		public function addPerson(e:MouseEvent):void
		{
			
			myList.addItemAt({label: "John Doe"}, 4);
		}
	}
}

 

 

When you load that up, after you push the button, it will add "John Doe" to the fifth position on the list. you will notice that it does not scroll the list no matter what position you are in when you press the button.

 

i was going through your code and noticed instead of 0 you were inserting at variable 'i'. is that because the list you are getting is in ascending order and you are trying to print it back out in descending order?

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
Please use plain text.
New Developer
adessugbaa
Posts: 8
Registered: ‎01-13-2011
My Device: Not Specified

Re: Adding items to QNX list without scrolling

I am using variable 'i' because the twitter API returns tweets ordered by when created_date (earlier rows are returned first). When i refresh the list, i need to append rows on top since they are more recent than existing rows in the list. I increment this so that if i have multiple new rows, i can append them on top of the list, but in the correct order.

 

I havent tried out your code (thanks), but i noticed that you use

mylist.addItem(...)

 

 

instead of

 

mydatasource.addItem(...)

 

 

I will update the forum once i make headway...

 

Thanks JRab.

Please use plain text.