質問

アプリ用のラジオボタンのグリッドを作成しようとしていますが、私が学んだことは、これが通常の使用ではないということです RadioGroup LinearLayoutを拡張し、手配しようとすると RadioButtons 内部でrelativelayoutを使用します RadioGroup RadioGroup は見えません Buttons 内側 RelativeLayout.

したがって、これを修正するために、LinearLayoutの代わりにRelativeLayoutを拡張するカスタムRadiogroupを作成したいと思います。

どうすればいいですか?

更新:私はあなたが言ったことをしましたが、私はこれらのエラーを持っています私はクラスファイルで修正する方法がわかりません:

Description Resource    Path    Location    Type
RadioGroup_checkedButton cannot be resolved or is not a field   RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 81 Java Problem
The constructor RelativeLayout.LayoutParams(int, int, float) is undefined   RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 265    Java Problem
The method setOnCheckedChangeWidgetListener(CompoundButton.OnCheckedChangeListener) is undefined for the type RadioButton   RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 363    Java Problem
The method setOnCheckedChangeWidgetListener(null) is undefined for the type RadioButton RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 377    Java Problem
VERTICAL cannot be resolved to a variable   RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 68 Java Problem
Widget_CompountButton_RadioButton cannot be resolved or is not a field  RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball  line 79 Java Problem
役に立ちましたか?

解決

あなたは取得する必要があります RadioGroupのソースコードから ここ, 、すべてのエントリを交換します LinearLayoutRelativeLayout.

このコードをプロジェクトのいくつかのXMLファイルに追加します(通常、その名前はattrs.xmlです):

<resources>
    <declare-styleable name="RadioGroup">
        <attr name="android:checkedButton" />
    </declare-styleable>
</resources>

交換 RadioGroupこれらのコンストラクター:

public RadioGroup(Context context) {
    super(context);
    if (!isInEditMode()) {
        init();
    }
}

public RadioGroup(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (!isInEditMode()) {
        TypedArray attributes = context.obtainStyledAttributes(
                attrs, R.styleable.RadioGroup, 0,
                android.R.style.Widget_CompoundButton_RadioButton);

        int value = attributes.getResourceId(R.styleable.RadioGroup_checkedButton,
            View.NO_ID);
        if (value != View.NO_ID) {
            mCheckedId = value;
        }

        attributes.recycle();
        init();
    }
}

から次のコンストラクターを削除します LayoutParams 内部クラス:

public LayoutParams(int w, int h, float initWeight) {
    super(w, h, initWeight);
}

のすべての発生を交換します setOnCheckedChangeWidgetListener() とのメソッド呼び出し setOnCheckedChangeListener() 方法。 重要: :この場合、このウィジェットを使用するコードからこのメソッドを使用することはできません。

これを試していませんが、これがうまくいくことを願っています。

他のヒント

Radiogroupのソースをからコピーします ここ 編集して、LinearLayoutの代わりにRelativeLayoutを拡張するように変更します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top