Android 5.0.2 ではカスタム ビュー コンストラクターが呼び出されません 質問する

Android 5.0.2 ではカスタム ビュー コンストラクターが呼び出されません 質問する

カスタムビューを作成しました:

public class SomeView extends View

カスタム ビュー コンストラクター:

public SomeView (Context context)
{
    super(context);
}
// Called when view is inflated from xml
public SomeView (Context context, AttributeSet attrs)
{
    super(context, attrs);
}
// Perform inflation from XML and apply a class-specific base style from a theme attribute.
public SomeView (Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
}

API 21 の 4 番目のコンストラクターも試しましたが、うまくいきませんでした。

public VeediView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
    super(context, attrs,defStyleAttr, defStyleRes);
}

XML レイアウトでこのビューを定義しており、問題なく動作します。

Galaxy S2 でのテストは正常に動作し、ビュー コンストラクターが呼び出されますが、Nexus-7 android 5.0.2 でアプリを実行すると、コンストラクターはまったく呼び出されません。

理由が分かりますか?

ルート化されたデバイスに関係しているのでしょうか?

関連する XML ビュー:

<com.package.name

        android:id="@+id/scene"
        android:onClick="startx"
        style="@style/txt_money_style"
        android:layout_width="72dp"
        android:layout_height="72dp"
        android:background="@drawable/wtbtn"
        android:layout_gravity="right"
        android:gravity="center_vertical|right"
        />

ベストアンサー1

bestway にはこのコンストラクターを使用する必要があると思います:

public SomeView (Context context)
{
    this(context , null);
}
// Called when view is inflated from xml
public SomeView (Context context, AttributeSet attrs)
{
    this(context, attrs , 0);
}
// Perform inflation from XML and apply a class-specific base style from a theme attribute.
public SomeView (Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
    // Initialize customize constructor here
}

おすすめ記事