We've been looking around for the implementation of the new material design swipe down to refresh on RecyclerViews with the loading circle coming down from bottom view same like new gmail app.i found so many things. But not getting new gmail app like example or demo .i already implement refreshlayout and recycleview.
But when scroll down to recycleview,how to put loading circle at the last of the record in recycleview. I want to get some idea to put in onscroll of recycleview.
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(int arg0) {
}
#Override
public void onScrolled(int arg0, int arg1) {
//add some data but not to show loader.
getDataFromDB();
}
});
hi If you wan't to develop such a kind of Layout then please follow this url, i was used it it's an awesome.
https://github.com/stormzhang/SwipeRefreshLayoutDemo
You should wrap all your layouts with
pull to refresh component for that.
after swipeRefreshLayout.setOnRefreshListener and set swipeRefreshLayout.setRefreshing(true); when you send API call
hear is awesome demo for both Scroll down to load data using recycleview and Swipe to RefreshLayout.
Related
I am working on an Android app that runs on only one devicerunning KitKat.
The smooth scrolling feature for a RecylerView I used that was working on other physical tablets and genymotion has unfortunately stopped working on the one device it needs to work on.
Instead of scrolling to a certain position it passes over the target position and scrolls all the way to the bottom and looks really bad.
I am able to track down the error to the abstract SmoothScroller in the RecyclerView class.
if (getChildPosition(mTargetView) == mTargetPosition) {
onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
mRecyclingAction.runIfNecessary(recyclerView);
stop();
} else {
Log.e(TAG, "Passed over target position while smooth scrolling.");
mTargetView = null;
}
I was using a SnappingLinearLayoutManager that I found online, but swapped it out with the normal LinearLayoutManager from Android, and still am having the same problem.
The list is 7 items long (user can see 4 at a time) and I scroll to the 5th item (position 4) item.
When I scroll to the 3rd I don't receive this error.
Also after I scroll the list up and down once, the error stops happening.
EDIT:
I am able to use layoutManager.scrollToPositionWithOffset(); But I am trying to do this with the smooth scroll animation.
Here is some of my code and details:
private void setupMainRecyclerViewWithAdapter() {
mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mainListRecyclerView.setLayoutManager(mainLayoutManager);
settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
settingsPresenter.getSettingsItems(),
settingsPresenter);
mainListRecyclerView.setAdapter(settingsMainListAdapter);
mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE));
}
#Override
public void scrollMainList(boolean listAtTop) {
if(listAtTop) {
mainListRecyclerView.smoothScrollToPosition(4);
moveMainMoreButtonAboveList();
} else {
mainListRecyclerView.smoothScrollToPosition(0);
moveMainMoreButtonBelowList();
}
}
If you call recyclerView.smoothScrollToPosition(pos) will be called immediately on the UI thread and if recyclerView's Adapter is too much busy to generating view items then the calling of smoothScrollToPosition will be missed then because recyclerView has no data to smooth scroll. So it's better to do that in a background thread by recyclerView.post(). By calling this it goes into the Main thread queue and gets executed after the other pending tasks are finished.
Therefore you should do something like this which worked for my case:
recyclerView.post(new Runnable() {
#Override
public void run() {
recyclerView.smoothScrollToPosition(pos);
}
});
Well, I realize it's too late, however I tried some different solutions and found one...
in custom LinearSmoothScroller I override updateActionForInterimTarget
#Override
protected void updateActionForInterimTarget(Action action) {
action.jumpTo(position);
}
It's appears not very smooth, but not instant in contrast with scrollToPositionWithOffset.
Just add one line for smooth scroll
recyclerView.setNestedScrollingEnabled(false);
it will work fine
Take a look at hasPendingAdapterUpdates(). You can use this along with a delay() for coroutines or Thread.sleep() to enable the backing data to be available before doing the scroll.
I have lots of contents on one page so i am using scrollview. I have one scan button at the bottom of the page, which i need to click many times to scan lots of barcodes. when i click on scan button, i am opening "BarcodeScanner" application that will sacn the barcode and returns the result to my application. so when i come back to my application, again i need to scroll the entire page to click the scan button which is at the bottom side. So is there any way to initialize the scroll at the bottom of the page? Please help
Thanks in advance
How do you think that you can initialise the scroll view.!! If you have lots of contents in a page you have to use scroll view for seeing all the contents. ! Try this, put your scroll view xml code in to botom of the xml code. and check.!!
Say your ScrollView id is scrollId, the code will lokk like this
scrollView = (ScrollView) findViewById (R.id.scrollId);
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
Try this
s.post(new Runnable() {
public void run() {
s.scrollTo(0, mScrollView.getBottom());
// or this
//s.fullScroll(s.FOCUS_DOWN);
}
});
I have a ListView that loads images to the ImageView asynchronously. To achieve this i am using Android-Universal-Image-Loader
But i would like to start loading this images only when they are visible in the listview. For example if the visible items of the listview are from 5 to 9, only those should be loaded. Also if the user scrolls very fast the ListView only when stopped those items should be loaded.
What is the best way to this?
If you use "view reusing" in your listview adapter then you shouldn't do anything. UIL do it for you. UIL won't load ALL scrolled images, only those which are got in task pool (you can set set pool size in configuration). If you use "view reusing" then images which were scrolled fast won't be loaded.
Look into example project on GitHub.
UPD: Since 1.7.0 version UIL have PauseOnScrollListener.
boolean pauseOnScroll = true;
boolean pauseOnFling = true;
listView.setOnScrollListener(new PauseOnScrollListener(pauseOnScroll, pauseOnFling));
Use an OnScrollListener, the onScrollStateChanged() method is called when the ListView switches between SCROLL_STATE_IDLE, SCROLL_STATE_TOUCH_SCROLL (slower scrolling), and SCROLL_STATE_FLING (faster scrolling). With this you can choose to load new images only when the states is "Idle" or "Touch".
Addition
In the first run the visible items of the ListView aren't shown. For example when the app starts if the ListView has 4 items visible those 4 images should be loaded.
I haven't used the Universal Image Loader myself, but from what you described below you need to know how many rows will be displayed before you start downloading. Try this:
Write a Runnable to start the asynchronous downloads.
Use your ListView's built-in Handler to call the Runnable after the rows have been drawn
For example:
private Runnable loadImages = new Runnable() {
#Override
public void run() {
// Start the asynchronous downloads
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mListView.post(loadImages);
}
The loadImages will be called after the ListView is drawn so you will know exactly how many rows are visible.
I have created a custom gallery in which I have implemented the drag and drop mechanism and rearranged the items.Drag happens during a long click event and fling also works fine.Now my problem is I am trying to auto scroll my gallery during a drag operation when a particular threshold value is reached on the left and side of the gallery,for this i tried using scrollto, setselection both of them seems to be working weird,can somebody help me out with this issue.
Instead of :
myGallery.setSelection(position);
Try :
myGallery.post(new Runnable() {
#Override
public void run() {
myGallery.setSelection(position);
}
});
The same thing with scrollTo should also work.
I hope it will help you.
in my app i have place a text view in the middle of the layout and when i scroll screen to left i want to show the google maps. So far i am showing the google aps by ontouch method.
how to perform this...
You can use a third party called SwipeView.
It's an extension of the HorizontalScrollView class.
USE THIS , its working fine and no delays
hor = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
hor.postDelayed(new Runnable() {
public void run() {
hor.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 1L);