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

Native Development

Reply
Contributor
xelexdu
Posts: 13
Registered: ‎02-08-2013
My Device: Z10
Accepted Solution

ListView end of List(Pull Up to load more)

[ Edited ]

I have Listview in which I want to add more Items when I am about to reach the end of List. Currently I am using onAtEndChanged signal to load more. But I would like to load more when I am about to reach around 80% of my list. I am also using custom datamodel for my listview. Which signal will help me to get the indexPath so that I can load more Items once specific indexPath is reached on my listview. 

 

I tried to implement it on C++ but I couldnt. Any help on this

 

QVariant listitem::data(const QVariantList& indexPath)
{
	int index = indexPath[0].toInt();
	return _itemList.at(index);
}

 

Developer
Brennan12325
Posts: 205
Registered: ‎05-15-2012
My Device: None

Re: ListView end of List(Pull Up to load more)

[ Edited ]

Hmm... this sounds more like "infinite scroll" like functionality you are looking for then pull up to refresh. This solution loads posts when you scroll an item into view that is 12 from the bottom of the list. You could do math based on your list size to do 80%. In any case, if you just want to load more items at the end of your list once you've scrolled through some amount of your list you can do this:

 

//Connect a scroll state handler. BAM!
	ListScrollStateHandler::create(redditPostsList)
		.onFirstVisibleItemChanged(this, SLOT(onFirstVisibleItemChanged(QVariantList)));

 then do this:

void App::onFirstVisibleItemChanged(QVariantList firstItem)
{
	int listIndex = this->m_RedditPostsModel->indexOf(this->m_RedditPostsModel->data(m_CurrentFirstVisibleListItem), 0);
	qDebug() << listIndex;

//load more posts when we are 12 posts from the bottom of the list. int threshold = m_CountOfPostsRetrieved - 12; if(listIndex > threshold) { //simulate pressing the load more button. callAFunctionToLoadMoreItems(); } }

 sorry if there are any errors in this code. This is the code I use but I simplified it a bit since I only use infinite scroll in some cases. This solution would always use infinite scroll.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Contributor
xelexdu
Posts: 13
Registered: ‎02-08-2013
My Device: Z10

Re: ListView end of List(Pull Up to load more)

Great. onFirstVisibleItemChanged signal did the magic. It works fine now. Thank you very much. :smileyhappy:
Developer
Kaz32
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha

Re: ListView end of List(Pull Up to load more)

Hi, I'm trying make load more like from this sample code, but fail.

Maybe I'm wrong implement the sample.

 

What is m_CurrentFirstVisibleListItem here, how to get the value?

 

 

Thanks