0

I'm extending the class SherlockListFragment

Inside this class I'm calling getListView() for retrieving the ListView related to my Fragment.

Below is shown the signature of the method getListView() that I'm using:

ListView android.support.v4.app.ListFragment.getListView()

The problem is that I want call setVerticalScrollbarPosition() over this ListView, but my project has minSDK = 7, so the following code:

getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);

gives me the error:

- Call requires API level 11 (current min is 7): 
     android.widget.ListView#setVerticalScrollbarPosition

How can I use this method, in order to work also in system with API level < 11 and > 7 ?

NOTE: I don't want use @suppressLint

GVillani82
  • 17,196
  • 30
  • 105
  • 172

1 Answers1

0

You'll need to say that the code running inside the method is for API 11 and above

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void doVertScrollThingy() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
    } else {
        // do something else, because setVerticalScrollbarPosition isn't supported
    }
}
bclymer
  • 6,679
  • 2
  • 27
  • 36
  • No, I want the same functionality for devices with API 7,8,9,10. I'm looking for some support library. – GVillani82 Oct 17 '13 at 18:09
  • Ah, my bad. Try checking out this thread - http://stackoverflow.com/questions/10826879/how-to-make-the-scrollbar-appear-on-the-left-side A solution was posted, with no comments saying it worked, but you can try it. It involves extending `ListView` – bclymer Oct 17 '13 at 18:12