I am using Room data base to fetch the data from the data base. Recyclerview I want to scroll to a particular position in recyclerview.
I have already tried list.setNestedScrollingEnabled(true)
StationListRepository stationListRepositoryOnlyActive = new StationListRepository(getApplicationContext());
stationListRepositoryOnlyActive.getActiveStationList().observe(this, new Observer>() {
#Override
public void onChanged(List OnlyActivestations) {
Log.d("OnlyActivestations", "" + OnlyActivestations.size());
assert OnlyActivestations != null;
if (OnlyActivestations.size() > 0 || FinalList.size() > 0) {
if (FinalList != null && FinalList.size() > 0) {
OnlyActivestations = sortList(OnlyActivestations);
FinalList.addAll(OnlyActivestations);
} else {
OnlyActivestations = sortList(OnlyActivestations);
FinalList = OnlyActivestations;
}
Log.d("FinalListSizeActive",""+FinalList.size());
detailsAdapter = new db_stationListAdapter(context, FinalList);
//recyclerView.setNestedScrollingEnabled(true);
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
staggeredGridLayoutManager.scrollToPosition(10);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
recyclerView.setAdapter(detailsAdapter);
detailsAdapter.notifyDataSetChanged();
runOnUiThread(new Runnable() {
#Override
public void run() {
// stopLoading();
stopAnimation();
}
});
}
}
});
I except the recycler view to auto scroll to the position 10
Try using the code below after you set the data to the adapter
recyclerView.smoothScrollToPosition(10);
or
You can add OnLayoutChangeListener to your RecyclerView.
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener(){
#Override
public void onLayoutChange(View v, int left, int top, int
right, int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
if (bottom < oldBottom) {
recyclerView.postDelayed(new Runnable() {
#Override
public void run() {
recyclerView.smoothScrollToPosition(10);
}
}, 100);
}
}
});
Related
My requirement is scrolling a ImageView left and right on top of a list of data in the Recyclerview. When Recyclerview is scrolled up the ImageView will move towards right until list reaches to the end and vice versa.
I have tried but facing few complexity any suggestions and reference will be very helpful.Or any logic will also be appreciated.
The problem what I facing now is that not able to handle the values in the addOnScrollListener
Sharing my code in the github: Github Link
MainActivity Code:
Sharing few lines of code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener, ClickEventLisener {
HorizontalScrollView v_scroll;
Button btn_left, btn_right;
int pos = 0;
int temppos = 0;
int initialpos = 0;
RecyclerView rv_recycler;
UserApapter adapter;
List<Users> user = new ArrayList<>();
Context mContext;
boolean isFirsttime = true;
ImageView iv_image;
String imageurl = "https://www.isometrix.com/wp-content/uploads/2017/03/featured-images-about.jpg";
int screenwidth = 0, imagewidth = 0;
int scroolby_val = 0;
#SuppressLint("ClickableViewAccessibility")
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
iv_image = findViewById(R.id.iv_image);
v_scroll = findViewById(R.id.v_scroll);
btn_left = findViewById(R.id.btn_left);
btn_right = findViewById(R.id.btn_right);
rv_recycler = findViewById(R.id.rv_recycler);
btn_left.setOnClickListener(this);
btn_right.setOnClickListener(this);
v_scroll.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
filllist();
getScreenSize();
setupimage();
getleftscroll();
// when scrolled to the leftmost position the variables are initialized
v_scroll.setOnScrollChangeListener(new View.OnScrollChangeListener() {
#Override
public void onScrollChange(View view, int i, int i1, int i2, int i3) {
initialpos = i;
if (i == 0) {
temppos = 0;
} else {
}
}
});
///not able to understand how to handle the values
//handling the scroll
rv_recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
getleftscroll();
if (dy > 0) {
temppos = temppos + scroolby_val;
v_scroll.scrollTo(temppos, 0);
Log.d("Scroll", "ScrollUp");
Log.d("temppos", "" + temppos);
} else {
if (initialpos != 0) {
temppos = temppos - scroolby_val;
v_scroll.scrollTo(temppos, 0);
Log.d("temppos1", "" + temppos);
Log.d("Scroll", "ScrollDown");
}
}
}
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
// Do something
} else if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
// Do something
} else {
// Do something
}
}
});
}
private void getScreenSize() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
Log.d("ScreenWidth", "" + width);
screenwidth = width;
}
private void setupimage() {
Glide.with(mContext)
.asBitmap()
.load(imageurl)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Log.d("ImageWitdh", "" + w);
iv_image.setImageBitmap(bitmap);
imagewidth = w;
}
});
}
/*
Logic I have implemented:calculated Imagewidth and screenwidth. Then minus it (imagewidth > screenwidth) and then divide it by the number of values in the array.
if the value is 0 then scrolling it by 1 per scroll or if the returned value is 3 then scrolling it by 3.
IOS team have done this way and working good for them but I am facing a minor issue here.
*/
private void getleftscroll() {
imagewidth = 2000;
if (imagewidth > screenwidth) {
int leftoutscreen = imagewidth - screenwidth;
scroolby_val = leftoutscreen / user.size();
if (scroolby_val == 0) {
scroolby_val = 1;
}
// temppos = 0;
Log.d("scroolby_val", "" + scroolby_val);
}
}
///button is just for demo purpose///
#Override
public void onClick(View v) {
if (v == btn_left) {
if (initialpos != 0) {
temppos = temppos - pos--;
v_scroll.scrollTo(temppos, 0);
Log.d("temppos", "" + temppos);
}
} else if (v == btn_right) {
temppos = temppos + pos++;
v_scroll.scrollTo(temppos, -temppos);
Log.d("temppos", "" + temppos);
}
}
private void filllist() {
user.clear();
for (int i = 0; i <= 300; i++) {
user.add(new Users(String.valueOf(i + 1), "name " + i));
}
inflateadapter();
}
private void inflateadapter() {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
adapter = new UserApapter(this, R.layout.row_users, user, this);
rv_recycler.setLayoutManager(mLayoutManager);
rv_recycler.setAdapter(adapter);
}
#Override
public void Currentposition(int position) {
Log.d("Currentposition", "" + position);
if (position == user.size() - 1) {
if (scroolby_val == 1) {
Log.d("scroolby_val", "" + scroolby_val);
Log.d("Inside", "Inside");
// v_scroll.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
// temppos = 1;
}
} else if (position == 0) {
temppos = 0;
}
pos = position;
}
#Override
public void ClickEventLisener(View view, int position) {
Toast.makeText(mContext, "" + position, Toast.LENGTH_SHORT).show();
}
}
Few things you may want to consider-
Don't use dy values from onScrolled callback directly to set scroll of v_scroll. There should be a logic to map scroll state of recycler view to the required scroll in v_scroll.
Don't use dy at all. Logic to set scroll of v_scroll should be based on the number of items in the list and the first/last visible child in it. (RecyclerView provides methods to get that.) You can run that logic from onScrolled callback.
I have this RecyclerView that functions as a ticker, the auto scrolling works fine at first but after a period of time it becomes strange (back and forth) and the RecyclerView gets stuck at an item without smooth scrolling anymore, can anyone help me.
this is my layout manager:
LinearLayoutManager layoutManager = new LinearLayoutManager(HomeActivity.this, LinearLayoutManager.HORIZONTAL, false) {
#Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(HomeActivity.this) {
private static final float SPEED = 5500f;// Change this value (default=25f)
#Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return SPEED / displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};
rvTicker.setLayoutManager(layoutManager);
this is my auto scrolling function:
public void autoScroll(){
speedScroll = 0;
handler = new Handler();
runnable = new Runnable() {
int count = 0;
#Override
public void run() {
if(count == tickerAdapter.getItemCount())
count = 0;
if(count < tickerAdapter.getItemCount()){
rvTicker.smoothScrollToPosition(++count);
handler.postDelayed(this,speedScroll);
}
}
};
handler.postDelayed(runnable,speedScroll);
}
SOLVED, I tweaked the autoscroll function:
public void autoScroll(){
speedScroll = 0;
handler = new Handler();
runnable = new Runnable() {
int count = 0;
#Override
public void run() {
if(count == tickerAdapter.getItemCount())
count = 0;
else {
if(count < tickerAdapter.getItemCount()){
rvTicker.smoothScrollToPosition(++count);
handler.postDelayed(this,speedScroll);
}else {
count = 0;
}
}
Log.wtf("tickerAdapter.getItemCount()", tickerAdapter.getItemCount()+"");
Log.wtf("count", count+"");
Log.wtf("++count", ++count+"");
Log.wtf("==============","=============");
}
};
handler.postDelayed(runnable,speedScroll);
}
I am using recylerview in my application and whenever new element is added to recyclerview, it scrolls to last element by using
recyclerView.scrollToPosition(adapter.getCount());
But, whenever keyboard opens(because of editTextView), it resizes the view and recyclerview gets smaller, but couldn't scroll to last element.
android:windowSoftInputMode="adjustResize"
I even tried to used the following code to scroll to last element, but it didn't work
editTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
recyclerView.scrollToPosition(chatAdapter.getItemCount());
}
}
});
I can try adjustPan to shift the pan up, but it is hiding my toolbar.
Please suggest any way to rectify the issue.
You can catch keyboard up changes using recyclerview.addOnLayoutChangeListener().
If bottom is smaller than oldBottom then keyboard is in up state.
if ( bottom < oldBottom) {
recyclerview.postDelayed(new Runnable() {
#Override
public void run() {
recyclerview.smoothScrollToPosition(bottomPosition);
}
}, 100);
}
Add this your activity or fragment:
if (Build.VERSION.SDK_INT >= 11) {
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v,
int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) {
recyclerView.postDelayed(new Runnable() {
#Override
public void run() {
recyclerView.smoothScrollToPosition(
recyclerView.getAdapter().getItemCount() - 1);
}
}, 100);
}
}
});
}
It works for me
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
I found the postDelayed to be unnecessary and using adapter positions doesn't account for when the recycler is scrolled to somewhere in the middle of an item. I achieved the look I wanted with this:
recycler.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
if (bottom < oldBottom) {
messageRecycler.scrollBy(0, oldBottom - bottom);
}
})
Although this an old question, I experienced this problem today and I found out that none of of the above method works. This is my solution
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v,
int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) {
final int lastAdapterItem = mAdapter.getItemCount() - 1;
recyclerView.post(new Runnable() {
#Override
public void run() {
int recyclerViewPositionOffset = -1000000;
View bottomView = linearLayoutManager.findViewByPosition(lastAdapterItem);
if (bottomView != null) {
recyclerViewPositionOffset = 0 - bottomView.getHeight();
}
linearLayoutManager.scrollToPositionWithOffset(lastAdapterItem, recyclerViewPositionOffset);
}
});
}
});
}
This works.
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private LinearLayoutManager mManager;
...
mManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mManager);
(initialize and set adapter.)
mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) scrollToBottom();
}
});
private void scrollToBottom() {
mManager.smoothScrollToPosition(mRecyclerView, null, mAdapter.getItemCount());
}
recyclerView.smoothScrollToPosition(recyclerView.getAdapter().getItemCount());
It works properly in support library version 27.0.1
There is nothing to set in the manifest.
val currentScrollPosition = 0
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
currentScrollPosition = recyclerView.computeVerticalScrollOffset() + recyclerView.computeVerticalScrollExtent()
}
override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) { }
})
storyList.addOnLayoutChangeListener { view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
if (bottom < oldBottom) {
if (currentScrollPosition >= recyclerView.computeVerticalScrollRange()) {
recyclerVIew.post {
recyclerView.overScrollMode = RecyclerView.OVER_SCROLL_NEVER
recyclerView.smoothScrollBy(0, recyclerView.computeVerticalScrollRange() - recyclerView.computeVerticalScrollOffset() + recyclerView.computeVerticalScrollExtent())
}
}
} else {
recyclerView.overScrollMode = RecyclerView.OVER_SCROLL_ALWAYS
}
}
layoutManager.scrollToPositionWithOffset(chatMessageAdapter.getItemCount() - 1, 0);
You can use addOnItemTouchListener to see the scrolling change:
private Boolean scrollListerActivate = true;
mRecyclerViewTop.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(scrollListerActivate == true) {
scrollListTopManager();
}
}
});
To scroll for last (or other) position you should use scrollListTopManager method:
public void scrollListTopManager() {
int position = 0;
int itemCount = mRecyclerViewTop.getAdapter().getItemCount();
position = itemCount - 1;
mRecyclerViewTop.scrollToPosition(position);
}
You should also use addOnItemTouchListener to stop using scrollListTopManager method, if you want to scroll manually:
mRecyclerViewTop.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
#Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent
motionEvent) {
scrollListerActivate = false;
return false;
}
#Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent)
{}
#Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {}
});
When you open chat you will get last message at the end of recycle view:
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
Below code will make adjustments according to keyboard!
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if ( bottom <= oldBottom) {
recyclerview.postDelayed(new Runnable() {
#Override
public void run() {
recyclerview.smoothScrollToPosition(bottom);
}
}, 100);
}
}
});
Bind the RecyclerView inside NestedScrollView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.NestedScrollView>
I'm new to Android. My requirement is to load extra data & set to the list view, when scroll reaches to the bottom. I am able to call next data but my previous data is hiding. How to correct this?
listView.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view,
int scrollState) {
// TODO Auto-generated method stub
}
#Override
public void onScroll(AbsListView view,
int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
// TODO Auto-generated method stub
if (listView.getLastVisiblePosition() == listView
.getAdapter().getCount() - 1
&& listView.getChildAt(
listView.getChildCount() - 1)
.getBottom() <= listView
.getHeight()) {
// scroll end reached
if (nextCall == null || nextCall == ""
|| nextCall.equals("null")
|| nextCall.equals("")) {
} else {
hostname=nextCall;
new ArticlesList().execute();
}
// Write your code here
}else{
}
}
});
dialog.dismiss();
} else {
Toast.makeText(getActivity(), "Went wrong",
Toast.LENGTH_LONG).show();
dialog.dismiss();
}
visit this which is discribe how to do pagination in listview. PagingListView
What you need is an endless scroll Listener, please take a look at this: https://github.com/codepath/android_guides/wiki/Endless-Scrolling-with-AdapterViews
just add this project to yours and use it like this:
yourListView.setOnScrollListener(new EndlessScrollListener() {
#Override
public void onLoadMore(int page, int totalItemsCount) {
... your asynchTask
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
super.onScrollStateChanged(view, scrollState);
}
});
In listView adapter:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (position == items.size() - 1)
{
items.add("new data1");
items.add("new data2");
notificationDataSetChanged();
}
//inject your view here
}
You lose your data, because you are overwriting a link to it. You should add data, not replace it.
I solved the same problem using following code snippet.
private int lastVisibleItem; private LinearLayoutManager linearLayoutManager; private int lastId; // get the last id of your post after first time load data from server. private int flag = 0;
linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView_news.setLayoutManager(linearLayoutManager);
recyclerView_news.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState){
super.onScrollStateChanged(recyclerView, newState);
}
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
new Handler().post(new Runnable() {
#Override
public void run() {
if (list_news.size() - 1 == lastVisibleItem) {
if (flag == 0) {
flag = 1;
getMoreData(lastId); // pass lastId to load next posts.
}
} else if (list_news.size() - 1 != lastVisibleItem) {
flag = 0;
}
}
});
}
});
Hope this will help. Thanks.
I got a listView, containing several items with the same hight in fullscreen. When i release scrolling, I want to scroll smooth automatically to that item, which takes the most space on the screen. The smoothscrolling itself works when i scroll to a random position and hit a button (for example when 60% of the firstVisible item is visible and 40% of the following item is visible it automatically scrolls smooth to the firstVisible item to be fullscreen after button-OnClick) see Code:
ListView mylistView= (ListView)findViewById(R.id.ListViewLayout);
int midScreen = mylistView.getMeasuredHeight() / 2;
public void onClick(View v) {
View v = mylistView.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
top =-top;
if (top <= midScreen) {
mylistView.smoothScrollBy(-top, 1000); // if first item takes more space, scroll up
} else {
mylistView.smoothScrollBy((midScreen*2)-top, 1000); // if second item takes more space, scroll down
}
now i want this working procedure to be called, when the list stops scrolling. I created an onScrollListener and in onScrollStateChanged i tried this if the listScroll stops (so state 0, idle):
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState==OnScrollListener.SCROLL_STATE_IDLE) {
View vX = mylistView.getChildAt(0);
int top = (vX == null) ? 0 : vX.getTop();
top =-top;
if (top <= midScreen) {
mylistView.smoothScrollBy(-top, 1000);
} else mylistView.smoothScrollBy((midScreen*2)-top, 1000);
}
}
The problem: instead of scrolling smooth 1second to that exact position to show the wanted item in fullscreen, it jumps as fast as it can. The smoothScrollBy is no more smooth when it is called in state 0. Why is that and is there any solution?
I think you can do something like that to let the smooth scroll.
public void scrollSmoothTopAfterMiddle( final int top ) {
final ValueAnimator anim = ValueAnimator.ofInt( top, 0 );
anim.addUpdateListener( new AnimatorUpdateListener() {
#Override
public void onAnimationUpdate( final ValueAnimator animation ) {
final int value = ( Integer ) animation.getAnimatedValue();
mListView.smoothScrollBy( ( midScreen * 2 ) - top, value );
}
} );
anim.setDuration( 250 );
anim.setInterpolator( new DecelerateInterpolator() );
anim.start();
}
public void scrollSmoothTopBeforeMiddle( final int top ) {
final ValueAnimator anim = ValueAnimator.ofInt( top, 0 );
anim.addUpdateListener( new AnimatorUpdateListener() {
#Override
public void onAnimationUpdate( final ValueAnimator animation ) {
final int value = ( Integer ) animation.getAnimatedValue();
mListView.smoothScrollBy( -top, value );
}
} );
anim.setDuration( 250 );
anim.setInterpolator( new DecelerateInterpolator() );
anim.start();
}
if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE ) {
final View vX = mListView.getChildAt( 0 );
int top = ( vX == null ) ? 0 : vX.getTop();
top = -top;
if ( top <= midScreen ) {
scrollSmoothTopBeforeMiddle( -top );
} else {
scrollSmoothTopAfterMiddle( ( midScreen * 2 ) - top );
}
}
Ok i managed to run the smoothScroll in a runnable with a handler and now it works!
If someone has the same problem, here comes the code
listViewAnlagen.setOnScrollListener(new OnScrollListener() {
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState==OnScrollListener.SCROLL_STATE_IDLE) {
View vX = listViewAnlagen.getChildAt(0);
int top = (vX == null) ? 0 : vX.getTop();
top =-top;
if (top <= mitteScreen) {
handler.post(obenRunnable);
} else {
handler.post(untenRunnable);
}
}
}
Handler handler = new Handler();
Runnable obenRunnable = new Runnable()
{
public void run()
{
View vX = listViewAnlagen.getChildAt(0);
int top = (vX == null) ? 0 : vX.getTop();
top =-top;
listViewAnlagen.smoothScrollBy(-top, 200);
}
};
Runnable untenRunnable = new Runnable()
{
public void run()
{
View vX = listViewAnlagen.getChildAt(0);
int top = (vX == null) ? 0 : vX.getTop();
top =-top;
listViewAnlagen.smoothScrollBy((mitteScreen*2)-top, 200);
}
};
});
private final Runnable SCROLLING_RUNNABLE = new Runnable() {
#Override
public void run() {
bannerItemRV.smoothScrollBy(pixelsToMove, 0);
mHandler.postDelayed(this, duration);
}
};
and We use bellow for
bannerItemRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastItem = bannerlinearLayoutManager.findLastCompletelyVisibleItemPosition();
if (lastItem == bannerlinearLayoutManager.getItemCount() - 1) {
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
Handler postHandler = new Handler();
postHandler.postDelayed(new Runnable() {
#Override
public void run() {
bannerItemRV.setAdapter(null);
bannerItemRV.setAdapter(bannerPagerAdapter);
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
}
}, 2000);
}
}
});
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
bannerItemRV.addOnItemTouchListener(new SwipeableItemClickListener(this, new com.talentedge.ui.widget.swipeDelete.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
bannerListResultData=bannerListResultDatas.get(position);
String url=bannerListResultData.getUrl();
if(!TextUtils.isEmpty(url) && !StringUtils.isNullOrEmpty(url)) {
showWebpage(Uri.parse(url));
}
}
}));