Android scroll up - android

I have two buttons Button 1, Button 2 placed horizontally like tabs. On Click of these button I am adding Linear Layout in Scroll View.
Now suppose I am clicking Button 1 and scroll down and immediately switch or click to Button 2 that scroll applies on newly added layout. I want every time on click of button content should scroll to top.
I have tried scrollview.scrollT0(0,0) and scrollview.scrollTo(0,scrollview.getTop()) but none of them is working.

I've ran into these types of issues before.
I suggest trying the following:
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.scrollTo(0, 0);
}
});
The reason this works is forces the action in the Main Thread which is where all UI Activity happens (safely, of course).

Try this . Just it is sample
private void scrollMyListViewToBottom() {
your_list.post(new Runnable() {
public void run() {
if (!running) {
// Select the last row so it will scroll into view...
your_list.setSelection(your_list.getCount() - 1);
running = true;
}
}
});
Note :
Before call this method just change Boolean running = false;

Related

ScrollView not scrolling to end while adding a new view android

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.

Programmatically make a click or touch an item in recyclerview

How to force a click or touch an item on a recyclerview?
I found people talking to use a command recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick() but recyclerView.findViewHolderForAdapterPosition(0) always returns null!
I want initially that the first recyclerview item is clicked/ touched.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
recyclerView.findViewHolderForAdapterPosition(position).itemView.performClick();
}
},100);

Android - scroll to a specific vieu with small device

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.

how to scroll horizontal scroll view without animation

The problem is that I'm using the fullScroll() and scrollTo() functions to scroll but it is animated and I need it happen without user observation.
Is there a way to solve this problem?
hScrollView.post(new Runnable() {
#Override
public void run() {
hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
});
Use this
// Disable the animation First
hScrollView.setSmoothScrollingEnabled(false);
// Now scroll the view
hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
// Now enable the animation again if needed
hScrollView.setSmoothScrollingEnabled(true);
You can use hScrollView.setSmoothScrollingEnabled(false); before running the Runnable command, this will give you the desired output
// Set smooth scrolling to false
hScrollView.setSmoothScrollingEnabled(false);
// Then call the fullScroll method
hScrollView.post(new Runnable() {
#Override
public void run() {
hScrollView.fullScroll(View.FOCUS_RIGHT);
}
});

Continuously Auto-Scrolling ListView

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 ;-)
}
});
}

Categories

Resources