13

次の警告が表示されました。

カスタム ビュー com/example/view/adapter/SomeAdapter に、ツールで使用されるコンストラクターがありません: (Context) または (Context,AttributeSet) または (Context,AttributeSet,int)

ArrayAdapter を拡張するいくつかの BaseAdapter を拡張するクラス SomeAdapter で

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

警告は具象アダプターには存在しますが、抽象 BaseAdapter には存在しません。そのコンテキストでこの警告について聞いたことがありますか?

AFAIK Android は、 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;
}

私が見る限り、私のクラス名は上記のパターンと一致しません。この警告を修正または抑制する方法を知っている人はいますか?

BaseAdapter の getView():

@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;
}
4

4 に答える 4

2

一部のレイアウト ツール (Eclipse 用の Android レイアウト エディターなど) は、次のいずれかのシグネチャを持つコンストラクターを見つける必要があります。 * View(Context context) * View(Context context, AttributeSet attrs) *View(Context context, AttributeSet attrs, int defStyle)

そのようなものを使用しておらず、すべてのプロジェクトでこの警告を取り除きたい場合は、次の場所にアクセスしてください。

Window -> Preferences -> Android -> Lint Error Checking.

ViewConstructorリストから見つけて、重大度を 'ignore' に設定します

于 2013-07-11T16:49:19.473 に答える