My ListView should automatically scroll to end, when new message received or sent.
But when I use Android keyboard to send message from EditText below ListView, ListView resized and new message, which I want to send, appears out of screen and I have to scroll down to see it, even if keyboard disappears and ListView resizes again.
To scroll ListView I use:
listView.postDelayed(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
}
}, 100);
but is not working correctly in my case.
Does anyone know why it may occur? Is there a way, which ALWAYS scroll ListView to end?
Thanks, your help is much appreciated!
Try this insead of your code:
listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
(or set it by XML layout).
You can try to add this line of code after you set selection to your list:
listView.smoothScrollToPosition(listView.getCount());
Resulting code should look like this:
listView.postDelayed(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
listView.smoothScrollToPosition(listView.getCount());
}
}, 100);
Set android:windowSoftInputMode in manifest for the activity to adjustPan|adjustResize.
Related
I would like to know how to automatically scroll a activity to the bottom.
I have this in my button where "sv" is my ScrollView:
sv.fullScroll(View.FOCUS_DOWN); //it works only in the button
But when I do it in the onCreate method nothing happens.
I also tried it with threads but nothing happens.
Could someone help me please.
Thank you!
Try this:
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
The scrollview must be created first, then you can scroll down. That's why we use post() here.
I have a scrollView in which while I am at end of the scrollView, on clicking a button at the end I need to show a view below that button. I am doing it by changing the visibility of that newly added view from GONE to VISIBLE. Its working but after clicking the button I am not able to see the newly added view i.e I need to scroll down the scrollView to show that view. Is there a way to scroll the ScrollView to that newly added view after clicking the button? and also to hide that view and scroll back to normal state after clicking that button again.
Thanks in advance!
it's an alternative which pretty much does the same thing.
Instead of Scrolling to the bottom of the screen, change the focus to a view which is located at the bottom of the screen.
That is, Replace:
scroll.scrollTo(0, scroll.getBottom());
with:
Footer.requestFocus();
Make sure you specify that the view, say 'Footer' is focusable.
android:focusable="true"
android:focusableInTouchMode="true"
or if above is not working try this
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
As the view that i was adding at the end was added with an expand animation so i used a countdown timer for it as follows:
new CountDownTimer(500, 1) {
public void onTick(long millisUntilFinished) {
myScrollView.scrollTo(0, R.id.bottomView);
}
public void onFinish() {
}
}.start();
Thats all.
I dont want to scroll it (becz i think it takes time and perfomance to scroll). I want to set it already scrolled to bottom at the start of the activity like whatsapp.
How could this be done?
If you want your ListView to be always scrolled at the bottom even on updating, you can add these attributes to the list:
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
Otherwise use :
listView.setSelection(adapter.getCount() - 1);
listview.setSelection(LastItemIndexInListView);
LastItemIndexInListView : size of listview - 1.
listView.post(new Runnable() {
#Override
public void run() {
listView.scrollTo(0, listView.getBottom());
}
});
Give this a shot.
listView.post(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount() - 1);
}
});
This should work for you
I want to scroll to a specific inflated view in ScrollView but after the scroll the item is either more below or partially shown.
Here's my code :
page.postDelayed(new Runnable() {
#Override
public void run() {
page.computeScroll();
page.smoothScrollTo(0, myView.getBottom());
// ...
}
}, 200);
If you have an idea, or you need more explanations, please tell me.
I have a Listview in Android. I want that the Listview continuously scrolls from top to bottom by itself. It should happen infinitely
And obviously I want to capture the click on any of the items of the Listview, post that the scroll will continue
Anybody having experience with such an implementation. Please help !!
http://groups.google.com/group/android-developers/msg/753a317a8a0adf03
To scroll automatically, you can use this: listView.smoothScrollToPosition(position);
private void scrollMyListViewToBottom() {
myListView.post(new Runnable() {
#Override
public void run() {
// Select the last row so it will scroll into view...
listView.smoothScrollToPosition(myListAdapter.getCount() - 1);
// Just add something to scroll to the top ;-)
}
});
}