Domanda

Sto cercando di fare una griglia di pulsanti di opzione per la mia app, quello che ho imparato è che questo non è possibile utilizzare RadioGroup regolare perché si estende LinearLayout e se si tenta di organizzare il RadioButtons utilizzando RelativeLayout all'interno del RadioGroup la RadioGroup non vede il Buttons all'interno del RelativeLayout.

Quindi, al fine di risolvere questo voglio fare un RadioGroup personalizzato che si estende RelativeLayout invece di LinearLayout.

Come posso fare questo?

UPDATE: ho fatto quello che hai detto, ma ho questi errori non so come risolvere nel file di classe:

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
È stato utile?

Soluzione

È necessario per ottenere il codice sorgente del RadioGroup da qui , sostituire tutte le voci di LinearLayout con RelativeLayout

Aggiungi questo codice in qualche file XML nel progetto (di solito il suo nome è attrs.xml):

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

Sostituire costruttori di RadioGroup con questi:

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();
    }
}

Rimuovi il seguente costruttore della classe interna LayoutParams:

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

Sostituire tutte le occorrenze di chiamate di metodo setOnCheckedChangeWidgetListener() con il metodo setOnCheckedChangeListener(). Importante :. In questo caso non sarà possibile utilizzare questo metodo da un codice che utilizza questo widget

non hanno provato questo, ma spero che questo lavoro sarà.

Altri suggerimenti

copiare il codice sorgente per RadioGroup da qui e modificare per cambiare per estendere RelativeLayout invece di LinearLayout.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top