2

I'm creating my own personalized ListView by extending the ListView itself. This particular ListView shouldn't have scrollbars.

  1. How can I disable the XML android:scrollbars attribute for my custom ListView?
  2. I can't find a way to disable them programmatically. What am I missing?

The answer from dzeikei's will disable the scrollbars programmatically and ignore any value from android:scrollbars but what I'm really asking on 1. is how to make android:scrollbars an invalid attribute for my custom component.

rfgamaral
  • 16,546
  • 57
  • 163
  • 275

2 Answers2

2

Updated OK as Richardo found out, seems like my original answer is the reverse way since the scrollbar is displayed internally :)

The correct way will be to call super.setHorizontalScrollBarEnabled(false) and super.setVerticalScrollBarEnabled(false) in the constructor and override setHorizontalScrollBarEnabled() and setVerticalScrollBarEnabled() do nothing :D

Override isHorizontalScrollBarEnabled() and isVerticalScrollBarEnabled() in your subclass to return false.

you could also override setHorizontalScrollBarEnabled() and setVerticalScrollBarEnabled() for good measure.

dzeikei
  • 2,256
  • 1
  • 21
  • 27
  • Thanks for that. But my main question is about the XML attribute thing as specified by the question title. Just to be clear, I know that overriding those methods will do the trick, but what I'm asking is if there's a way to make `android:scrollbars` invalid for my custom component. Maybe I should clear that up in the question... – rfgamaral Mar 17 '12 at 01:23
  • I'm pretty sure `` works similar to method declaration, you cannot undeclare something in the subclass. You are welcome to prove me wrong though :) – dzeikei Mar 17 '12 at 02:23
  • 1
    I just tested your suggestion and overriding both `isHorizontalScrollBarEnabled()` and `isVerticalScrollBarEnabled()` to return false didn't do anything, the scrollbars still show. I actually had to call the `set` methods on the constructor and set them to false. But to prevent them from being set to true I need to override the `set` methods and always set them to false. Please update your answer as you see fit. – rfgamaral Mar 17 '12 at 03:24
0

Try keeping @null for android:scrollbars. Am not sure. But, I usually use @null when i want to remove anything from XML attributes.

Pavandroid
  • 1,586
  • 2
  • 15
  • 30