360SDN.COM

The method initializeScrollbars(TypedArray) is undefined for the type PLA_AbsLis

来源:  2017-07-02 14:33:58    评论:0点击:

The method initializeScrollbars(TypedArray) is undefined for the type PLA_AbsListView

 

这个错误,很多人认为是  API版本太低,initializeScrollbars这个函数没有办法用,

 

真正的解决方法是采用:反射的机制来搞定,因为,我们知道方法名,方法的参数,所以就可以这样做,

 

        final TypedArray a = context.getTheme().obtainStyledAttributes(new int[0]);
        try {
            // initializeScrollbars(TypedArray)
            Method initializeScrollbars = android.view.View.class.getDeclaredMethod("initializeScrollbars", TypedArray.class);
            initializeScrollbars.invoke(this, a);
        } catch (Exception e) {
            e.printStackTrace();
        }

 

这种方法是最有效果的,

 

换成这个
        try {
      final Method initializeScrollbars =
             android.view.View.class.getDeclaredMethod("initializeScrollbars",
                     TypedArray.class);
      initializeScrollbars.invoke(this, a);
      } catch (NoSuchMethodException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

 

 

一般这种错误是出现在自定义的view中的构造函数里面。




Use reflection to invoke initializeScrollbars() in your custom view's constructor. This could fail in future API versions if the method initializeScrollbars() is actually removed or renamed. For example:

In your custom view (e.g. MyCustomView.java):

public MyCustomView(Context context) {
    super(context);

    // Need to manually call initializedScrollbars() if instantiating view programmatically
    final TypedArray a = context.getTheme().obtainStyledAttributes(new int[0]);
    try {
        // initializeScrollbars(TypedArray)
        Method initializeScrollbars = android.view.View.class.getDeclaredMethod("initializeScrollbars", TypedArray.class);
        initializeScrollbars.invoke(this, a);
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
        e.printStackTrace();
    }
    a.recycle();
}

 

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权