自定义视图是缺少构造函数中使用由适配器工具自定义、适配器、视图、函数

2023-09-08 09:36:37 作者:背影遥不可及

我得到了以下警告:

  

自定义视图COM /例子/查看/适配器/ SomeAdapter缺失  构造函数通过工具使用:(上下文)或(上下文,AttributeSet中)或  (上下文,AttributeSet中,INT)

在我的课SomeAdapter延伸一些BaseAdapter延伸ArrayAdapter

 公共类SomeAdapter扩展BaseAdapter {}公共抽象类BaseAdapter扩展ArrayAdapter< SomeModel> {} 

警告存在于混凝土适配器,但不是在抽象BaseAdapter。有没有人听说过这样的警告在这方面的?

据我所知的Andr​​oid检查它们被通过ViewConstructorDetector:

 私有静态布尔isViewClass(ClassContext背景下,ClassNode节点){    字符串superName = node.superName;    而(superName!= NULL){        如果(superName.equals(机器人/视图/视图)// $ NON-NLS-1 $                || superName.equals(机器人/查看/ ViewGroup中)// $ NON-NLS-1 $                || superName.startsWith(机器人/空间/)// $ NON-NLS-1 $                &功放;&安培; !((superName.endsWith(适配器)// $ NON-NLS-1 $                        || superName.endsWith(控制器)// $ NON-NLS-1 $                        || superName.endsWith(服务)// $ NON-NLS-1 $                        || superName.endsWith(提供者)// $ NON-NLS-1 $                        || superName.endsWith(过滤器)))){// $ NON-NLS-1 $            返回true;        }        superName = context.getDriver()getSuperclass之(superName)。    }    返回false;} 

据我可以看到我的类名称不匹配上面的图案。有没有人有任何想法如何修复或SUP preSS此警告?

getView()中的BaseAdapter:

  @覆盖公众最终查看getView(最终诠释的位置,最后查看convertView,最终的ViewGroup父){    查看查看= convertView;    如果(空==视图){        鉴于= createNewView(父母,位置);    }其他{        reuseOldView(视图位置);    }    返回视图。} 
如何使用VMware ESX基础架构中的VI Client搜索工具

解决方案

在您的CustomView类添加构造函数:

 公共CustomView(上下文的背景下){    超级(上下文);}公共CustomView(上下文的背景下,ATTRS的AttributeSet){    超(背景下,ATTRS);} 

I got the following warning:

Custom view com/example/view/adapter/SomeAdapter is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int)

in my class SomeAdapter which extends some BaseAdapter which extends ArrayAdapter

public class SomeAdapter extends BaseAdapter{}
public abstract class BaseAdapter extends ArrayAdapter<SomeModel>{}

The warning exists in the concrete adapter but not in the abstract BaseAdapter. Has anyone ever heard of this warning in that context?

AFAIK Android checks classes for they are extending views by checking the name of the super classes via ViewConstructorDetector:

 private static boolean isViewClass(ClassContext context, ClassNode node) {
    String superName = node.superName;
    while (superName != null) {
        if (superName.equals("android/view/View")                //$NON-NLS-1$
                || superName.equals("android/view/ViewGroup")    //$NON-NLS-1$
                || superName.startsWith("android/widget/")       //$NON-NLS-1$
                && !((superName.endsWith("Adapter")              //$NON-NLS-1$
                        || superName.endsWith("Controller")      //$NON-NLS-1$
                        || superName.endsWith("Service")         //$NON-NLS-1$
                        || superName.endsWith("Provider")        //$NON-NLS-1$
                        || superName.endsWith("Filter")))) {     //$NON-NLS-1$
            return true;
        }

        superName = context.getDriver().getSuperClass(superName);
    }

    return false;
}

As far as I can see my class names don't match the pattern above. Does anyone has any idea how to fix or suppress this warning?

getView() in BaseAdapter:

@Override
public final View getView(final int position, final View convertView, final ViewGroup parent) {
    View view = convertView;
    if (null == view) {
        view = createNewView(parent, position);
    } else {
        reuseOldView(view, position);
    }
    return view;
}

解决方案

In your CustomView class add constructors:

public CustomView(Context context) {
    super(context);
}
public CustomView(Context context, AttributeSet attrs) {
    super(context, attrs);
}