Android listview settings sometimes ignored? - android

I have my listview doing somethings like scrollToPosition , this makes the listview automatically scroll to a part of the list. MOST of the time it works, sometimes it doesn't happen, such as when there are other things happening quickly like button presses or when the scrolling is supposed to happen after a thread ends.
It seems having anything in the way prevents the scrolling. Thoughts, suggestions?

Related

EditText in RecyclerView causes scroll to jump around

I have an EditText inside a RecyclerView. Whenever I press any key on the keyboard, the RecyclerView scroll jumps around.
At first I thought it might be that the list is constantly updating on every key stroke, but that is not the case. I only update the list items once.
Please don't suggest using adjustPan. Yes, that will solve the problem in portrait, since the list isn't very long, but the problem still occurs on small screens or in landscape mode when the list doesn't fit on screen.
I've also tested with and without nestedScrollingEnabled="false", which didn't help either.
Here's a GIF showing what's happening. In this case I'm just pressing the backspace key over and over again.
What is causing this, and how do I prevent it?

Scrolling of list below another view

I have seen an app which has different type of scrolling. I hope images attached will be able to explain it. Here the list when scrolled up, moves up by taking DownloadAll, Playall button up too. Later on DownloadAll and PlayAll button stops going up and only the list scrolls up.
I don't know what this is called as. I tried searching, but could not find anything similar.
How can I achieve this type of scrolling?
Take a look at "Libraries for developers" it has a section of listview where you can find different styles of listviews (plus scrolling animations such as sticky, animated scrollview, flabby etc...)

ListView with footer attached, smoothScrollToPosition not functioning correctly

I'm working with a rather large layout that includes a ListView and a LinearLayout beneath it as a footer. I first tried to wrap this in a ScrollView to make the whole layout scrollable, but ran into problems due to both the ListView and the ScrollView being incompatible with each other since they both have scrollable features. So, a workaround was to include the LinearLayout as a footer to the ListView.
Now, in the LinearLayout, I have buttons at various places that the user can click to return to the top of the page. The behaviour I am getting from this is odd, to say the least.
If I have not scrolled down too far, the buttons function normally. However, if I scroll down a bit too far, then clicking the button (even the same buttons that previously worked) will result in the layout scrolling up to roughly half of the way up the listview instead of the top.
Here is the method that does the scrolling, it's rather simple:
public void backToTop(View view) {
lv = (ListView)findViewById(R.id.listview);
lv.smoothScrollToPosition(0);
}
This method is triggered when any of the buttons are clicked.
I have also tried to use the "scrollTo(0, 0)" function, but that failed to do anything.
Any help would be appreciated!
**edit: After testing some more, it appears as though the point where scrolling does not seem to function properly anymore is when the listview is no longer visible on the page. As soon as I scroll past it, the buttons begin to function incorrectly.
Edit 2: SOLVED. My solution: I changed the line
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!
My solution: I changed the second line of my backToTop method:
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!

Buttons on scrollview issue

This is my first question on StackOverflow, but I've learned a lot here already.
Now I have a problem, which I couldn't solve.
I have a horizontal scroll view with some buttons on it (let's say 20 buttons). When I scroll and stop the scrollview, it needs some time to accept clicks by buttons. I mean - onClick method desn't fire.
It could be observed best when scrolling is fast, and stops rapidly because of coming to the end of scrollbar.
Then it takes 2 clicks to get the button action.
I think this is some focus problem, or it's about of scrollview events implementation on scrolling.
As a ScrollView moves along, it unloads out-of-focus things and loads coming-into-focus things. This may be why the button's click takes a bit to register.
A project of mine learned this the hard way after we had already implemented everything in it. It worked great before the ScrollView had large amounts of content. Then once it did, it was super laggy and that's when we learned this.

Android ListView with clickable items in it's rows causes problems continuing scrolling

I've been trawling the internet looking for an answer for several hours, but I can't seem to find anyone who has been able to solve this.
I've got a listview which uses a custom adapter. A row looks like this
The list is filled by an array. Everything works great.
Now, I want the ImageView and the ToggleButton to react to clicks, so I implement the OnClickListener in my adapter, put the items position in each view's tag, and then I set their onclicklistener to this.
Works great, except now I can't use the onListItemClick for starting an activity for the item! OK, I say, I just make the relativelayout holding the text in the middle there use the same onclicklistener. Works great. Everything is clickable, and life is good.
EXCEPT! Now, when I scroll the list, I cannot "continue" the scroll by just flinging again. This causes the scrolling to stop, and I have to fling once more to get it going again. It seems the onclick-thingy causes the fling-motion to be interpreted as a tap or something (it does not trigger the logic within onClick).
I know that this is possible by just going to the phone list on my HTC Hero, which has exactly the kind of layout and behaviour I want from my app. This app even seems to have the onItemClickListener working.
So how can I make sure the list keeps scrolling, and still be able to click the togglebutton, listitem and the imageview? I've been stuck on this all day, and it's giving me a headache :(
Another quick search before I go home, and I came across this:
How to fire onListItemClick in Listactivity with buttons in list?
CodeFusionMobile mentions setting the android:descendantFocusability property of the list layout to "blocksDescendants", and so I tried doing that. Everything works as expected now. Scrolling works, onListitemClicked works, clicking the ToggleButton works, clicking the ImageView works.
Just to make it clear... In the parent RelativeLayout, right at the top of the row.xml, I added
android:descendantFocusability="blocksDescendants"

Categories

Resources