2011-03-12 5 views

Répondre

0

RadioGroup étend LinearLayout. Alors deux rangs est impossible, je pense.
Créer un wrapper qui enveloppe le groupe de RadioGroups et implémente/délègue la vérification/décochage et les écouteurs d'événement.

0

En fait, c'est plutôt possible ... au moins en partie!

Ce que vous devez faire est de créer un RelativeLayout qui sera enveloppé entre votre RadioGroup et votre RadioButton s. Ensuite, pour chaque RadioButton, donner une règle RelativeLayout pour sélectionner la position, comme ceci:

RadioGroup fromRadioGroup = new RadioGroup(this); 
    RelativeLayout fromChoice = new RelativeLayout(this); 
     RadioButton fromNow = new RadioButton(this); 
     fromNow.setText(R.string.Now); 
     fromNow.setId(1000); 
    fromChoice.addView(fromNow); 
     RadioButton fromTomo = new RadioButton(this); 
     fromTomo.setText(R.string.Tomorrow); 
     RelativeLayout.LayoutParams relParams1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams1.addRule(RelativeLayout.RIGHT_OF, 1000); 
     fromTomo.setLayoutParams(relParams1); 
    fromChoice.addView(fromTomo); 
     RadioButton fromNextW = new RadioButton(this); 
     fromNextW.setText(R.string.NextWeek); 
     fromNextW.setId(100100); 
     RelativeLayout.LayoutParams relParams2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams2.addRule(RelativeLayout.BELOW, 1000); 
     fromNextW.setLayoutParams(relParams2); 
    fromChoice.addView(fromNextW); 
     RadioButton fromNextM = new RadioButton(this); 
     fromNextM.setText(R.string.NextMonth); 
     fromNextM.setId(100200); 
     RelativeLayout.LayoutParams relParams3 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams3.addRule(RelativeLayout.BELOW, 1000); 
     relParams3.addRule(RelativeLayout.RIGHT_OF, 100100); 
     fromNextM.setLayoutParams(relParams3); 
    fromChoice.addView(fromNextM); 
fromRadioGroup.addView(fromChoice); 

Maintenant, les RadioButton s affichent sur deux lignes, mais ils ne réagissent pas dans le cadre du même RadioGroup plus. .. fondamentalement, je peux sélectionner plus d'une radio du même groupe, et en regardant ce que fromRadioGroup.getCheckedRadioButtonId() renvoie, (-1), il est clairement pas considéré RadioButton comme enfant ... sorcière nous amène au point de solution presque inutile . Ou peut-être y at-il un moyen de forcer les enfants à retourner à leur RadioGroup mais je n'en ai pas encore trouvé.
À la vôtre.

Questions connexes