Android PullToRefresh onScrollListener not working - android

I have chrisbanes PullToRefresh lib working in my project. Now I need to intercept scroll events to add some logic, it seems that the library is prepared to set onScrollListener, and I tried to add one with
myList.setOnScrollListener(this);
and
myList.getRefreshableView().setOnScrollListener(this);
but the listener methods are never called. I guess this has something to do with PullToRefreshBase class overriding onTouchEvent and onInterceptTouchEvent, but can't figure out how can I fix the issue, or maybe I'm missing something simple.
Did anyone succeeded adding onScrollListeners to PullToRefresh List?

For the change you will considered to listen the scroll bar .
To use the Scroll state change Listener I hope it will use to get the solution for you...
listStudies.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if ((MainActivity.listsize - MainActivity.currentlistitemposition) <= 3
&& listagain == 0) {
listagain = 1;
System.out.println(MainActivity.listsize);
System.out.println(MainActivity.currentlistitemposition);
currentPage++;
try {
performRequest(currentPage);
} catch (Exception e) {
// Toast.makeText(MainActivity.this,
// "Error occuered during the Request...",
// Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});
Because Am also using chrisbanes PullToRefresh lib So i hope it will usefull for you..Best of Luck...

Related

How to load more records on scrolling in tv android box

I have set up setOnScrollListener event on my listview its working good in mobile here is my code
movieList.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
userScrolled = true;
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(userScrolled && (firstVisibleItem + visibleItemCount >= totalItemCount)){
pageNum++;
int index = movieList.getFirstVisiblePosition();
float indexY = movieList.getScrollY();
load_loader.setVisibility(View.VISIBLE);
getMovies();
movieList.setSelection(index);
userScrolled = false;
}
}
});
Now i have installed my app to android tv box my full app is working good in tv box but list view not loading more records i think because of touch scroll tv is not touch its operated by remote navigation please help me to solve this problem thank you
Try setting listView.setItemsCanFocus(true); to your ListView so that focusable views inside of your listItems won't be ignored. Source.
You may also check this documentation on how you can actually navigate around your app when using remote control buttons instead of a touch screen.

OnScoll called multiple times in ListView

While using this, if i scroll a small amount, why is onScroll() called for 20 or so times i.e 5-6 times for each firstVisibleItem. Why not its called once for each scroll action?
listView.setOnScrollListener(new OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d("hey","called"+firstVisibleItem);
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}
});
If you look at implentation of ListView, you can see that mOnScrollListener.onScroll is called only once in ListView, actually in invokeOnItemScrollListener() method.
void invokeOnItemScrollListener() {
if (mFastScroll != null) {
mFastScroll.onScroll(mFirstPosition, getChildCount(), mItemCount);
}
if (mOnScrollListener != null) {
mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount);
}
onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these.
}
So let's try find some usages of invokeOnItemScrollListener(). We got a lot, including usages in AbsListView. In AbsListView, invokeOnItemScrollListener() is called indirectly every time in onTouchMove method. So now, it should be clear why you receive onScroll callback so many times.

Android: ListView onScrollListener doesn't stop listening

I've implemented ListView in my application and working on onScrollListener. The ListView is working fine and in the onScroll() method of the onScrollListener, i'm trying to show a progressbar when the user has scrolled to the bottom.
The problem is that the listener doesn't stop listening and there are multiple progressbar loading on the screen if the user is trying to scroll even more. I don't have any idea how to solve this.
I want the onScrollListener to stop listening when the progressbar shows.
Please help
list.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (list.getLastVisiblePosition() == list.getAdapter().getCount() -
&& list.getChildAt(list.getChildCount() - 1).getBottom() <= list.getHeight()) {
ProgressBar pb = new ProgressBar(getActivity());
pb.setLayoutParams(pbParams);
linearLayout.addView(pb);
}
}
});
Thanks in advance
Can't you just check to see if there is already a progress bar and not add another?

Where Am I in Listview Android?

I use Listview with Remote Control (Q1 Himedia SettopBOx)
Now down and up keydown ،How do I know where I am in listview
for example: when arrived in last item in listview then list refreshed or going to first item?
Please Help Me....
thanks
Take a look at OnScrollListener of ListView. You can set a new callback using ListView.setOnScrollListener() and get first visible item position and number of visible entries by implementing onScroll function of the listener.
Use an OnScrollListener for the listview like so.
myListView.setOnScrollListener(new OnScrollListener()
{
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
// Your code goes here. Determine the position with the firstVisibleItem.
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING)
{
Log.d(TAG, "User is flinging through the view");
}
}
});

onChildClick events stop after scrolling a listview

I have an app that uses an ExpandableListView widget filled with items via a BaseExpandableListAdapter. The app was built for the Android Version 1.6, and when I test it using the Android Emulator (version 1.6 build) everything works fine. I can scroll the list up and down and when I tap on any items in the list I get a onChildClick() event.
However, when I try to run this same app on an real Android phone (running Gingerbread), I only get onChildClick() events if I don't scroll the ExpandableListView. If I scroll the list too much, I no longer get onChildClick events (nor itemClickEvents also).
So I'm baffled. Why do I not get any onChild or onItem click events for the listview items after I scroll it? Note, that if I scroll it just a small amount (say, 2 or three lines) I do get click events, but any more scrolling and then I no longer get click events for any item in the list.
Any suggestions or advice would be appreciated.
Thanks.
Ok, I'm answering my own question here for others who may have the same problem. The issue I'm experiencing seems to be related to the focus status of the ExpandableListView Widget. When I scroll the list, the ListView widget seems to lose focus and I can't select any of the listed items. I'm not sure what the best way is to correct this, but I did get this to work.
I added a scroll listener for the ListView widget as show:
getExpandableListView().setOnScrollListener(this);
I then added a method to my activity that would set the focus back to the ListView Widget once it is finished scrolling:
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
// - this method is called when there is a scroll event in the main ExpandableListView widget.
// - after the user stops scrolling the listview, make sure to set the focus to the widget
if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE )
{
ExpandableListView elv = getExpandableListView();
elv.requestFocusFromTouch();
}
}
Now that seems to fix my issue. I'm sure there's a better way (and if you know of one, please post it here), otherwise my "hack" seems to work ok.
Hope it helps someone with a similar issue.
Thanks, this answer solved my problem on losing focus on while scrolling.
ListView mRecentSearchList;
mRecentSearchList.setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//adapter.notifyDataSetChanged();
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
//adapter.notifyDataSetChanged();
if(scrollState == OnScrollListener.SCROLL_STATE_IDLE ||scrollState == SCROLL_STATE_TOUCH_SCROLL || scrollState == SCROLL_STATE_FLING)
{
mRecentSearchList.requestFocusFromTouch();
}
}
});
I have experienced exactly the same problem and I found that it was caused not by list itself but adapter(ResourceCursorTreeAdapter). To prevent groups to collapse I was doing a hack as follows in my adapter:
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View view = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView list = (ExpandableListView) parent;
list.expandGroup(groupPosition);
return view;
}
If you do the same, please try replacing this with different solution.
In my case I've used the same solution proposed by cohoman, however the requestFocus() method provided me a better user experience:
navList.setOnScrollListener(new OnScrollListener()
{
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
if(scrollState == OnScrollListener.SCROLL_STATE_IDLE)
{
navList.requestFocus();
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
// TODO Auto-generated method stub
}
});

Categories

Resources