How can I make a scroll view scroll to the bottom? - android

I have tried this using methods I could find on internet.
My program is a listview containing 3000 webviews (webview inside a cardview).
(I dont think this issue is because webview being a scrollable one)
When I start the activity it is scrolled to bottom, but not the very bottom, just few webviews (around 10) out of 3000 stays below the screen.
I suspect the issue is because, the webview resizes just in milliseconds after it is loadData with a local String.
I have tried,
mainListView.post(new Runnable() {
#Override
public void run() {
// Select the last row so it will scroll into view...
mainListView.setSelection(getCount() - 1);
}
});
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true"
both resulting same.

Try:
myListView.setSelection(myListAdapter.getCount() - 1);
First you get the total count of the item available in your listview, the set the selection to the last item by minus 1, since the setSelection() start from 0.

Related

RecyclerView - Any way to get how many items are visible on screen before user starts scrolling?

One of my activities contain a RecyclerView.
On launching the activity, I want to know how many times onBindViewHolder() would run before user does any scrolling. Using logging, I checked that it runs almost as many times as the number of items visible on the screen. So essentially I want to know how many items are visible on the screen.
getItemCount() gives the total number of items. This is not what I want.
Is there any other way or method to get only the count of visible items?
I checked this post, but it did not help my case - Get visible items in RecyclerView
To get RecyclerView visible count you can use layoutManager.getChildCount().
But you have to use like this :
layoutManager.postOnAnimation(new Runnable() {
#Override
public void run() {
System.out.println("Visible count " + layoutManager.getChildCount());
}
});

Android: Setting ListView fast scroll based on visible positions

I am trying to set the fast scroll enabled and visible if there are more items in the list than are currently visible. After setting the adapter, the ListView's count is properly increased but the last visible position is not. As a result I am currently posting a Runnable to wait until the ListView has figured out what items are / aren't visible. The code is as follows:
listView.post(new Runnable(){
#Override
public void run() {
if(listView.getLastVisiblePosition() < (listView.getCount() - 1)){
listView.setFastScrollAlwaysVisible(true);
listView.setFastScrollEnabled(true);
}
}
});
This solution works fine, but feels a bit hackish. Is there a way to know when the last visible position is updated without posting the runnable? Thanks in advance!

Not able to scroll till end in android

I have TextView+webview as ListItem of ListView. When I change orientation. I am reloading all files as well setting adapter again and I am calling following code to select item from list programtically so I can get onItemClick call same ways as user would have clicked.
if(position!=-1 && getAdapter()!=null){
requestFocusFromTouch();
performItemClick(
getAdapter().getView(position,
null, null), position,
getAdapter().getItemId(position));
}
Now when I change orientation of screen, the selected item's webview is not scrolling till the end. It seems that it is not changing its scrolled position when we change orientation (Even though we reset adapter).
I tried requestlayout(), forcelayout(), invalidate(),reload() method of webview but none of them seems to be working.
You probably have your WebViews heights set to wrap_contents. This means that their heights are 0 when the list is loaded and they expand to a > 0 height at some point. One way to solve your issue would be to wait for all of the webviews to call onSizeChanged before scrolling, another option would be to re-position the list every time the lists contents change size.

Scrolling android gridview blocking userinteraction

I have a gridview placed inside scrollview.
When app is launched the 12 items are displayed(page 1) in gridview.
WHen user scrolls and reaches the end of the scroll, next 12 items of next page is fetched via webservice, added to the initial array of items.
the notifydatasetchanged of gridview adapter is called and also the height of gridview is set dynamically.
But the issue is in point #3. This is blocking the user interaction for 1-2 seconds.
Please help.
Have you tried performing the update in a thread?
runOnUiThread(new Runnable() {
public void run() {
//Update the grid view and set height.

Android: scroll to the bottom of the view

I have a ListView containing some custom Views, and at the end of my list, a FooterView containing a Button.
When I click the button, it adds a view at the end of my ListView. But the cursor of the scrollbar stays at its position.
Now, what I want is to auto-scroll to the end of the list (so the user can see the new item).
Do you have any idea on how I can do that?
i think you will find you happyness here
ListView has a method just for this: smoothScrollToPosition
Once you've added the new item, just calculate the length of the list and pass that (remembering zero-indexing) to the above method
Try this one.. it will solve your problem, i tried it and it works great.
listView.post(new Runnable(){
public void run() {
listView.setSelection(listView.getCount() - 1);
}});

Categories

Resources