android - How can I create A radiogroup 2x2? -


hello want create radiogroup 2x2 achieved using 2 radiogroup. problem right can select 2 radiobutton instead of one.. how can try ?

i precise use kotlin develop.

thank !

here have similar question gridlayout 3x3 because can't want want trivialy, should acept 1 of answers of question above. did:

public class gradiogroup {      list<radiobutton> radios = new arraylist<radiobutton>();      /**      * constructor, allows pass number of radiobutton instances,      * making group.      *      * @param radios      *            1 radiobutton or more.      */     public gradiogroup(radiobutton... radios) {         super();          (radiobutton rb : radios) {             this.radios.add(rb);             rb.setonclicklistener(onclick);         }     }      /**      * constructor, allows pass number of radiobuttons      * represented resource ids, making group.      *      * @param activity      *            current view (or activity) radiobuttons      *            belong.      * @param radiosids      *            1 radiobutton or more.      */     public gradiogroup(view activity, int... radiosids) {         super();          (int radiobuttonid : radiosids) {             radiobutton rb = (radiobutton)activity.findviewbyid(radiobuttonid);             if (rb != null) {                 this.radios.add(rb);                 rb.setonclicklistener(onclick);             }         }     }      /**      * occurs everytime when 1 of radiobuttons clicked,      * , deselects others in group.      */      public void addradiobuttonstogroup(radiobutton rb){         radios.add(rb);         rb.setonclicklistener(onclick);     }      onclicklistener onclick = new onclicklistener() {          @override         public void onclick(view v) {              // let's deselect radios in group             (radiobutton rb : radios) {                  viewparent p = rb.getparent();                 if (p.getclass().equals(radiogroup.class)) {                     // if radiobutton belongs radiogroup,                     // deselect radios in                     radiogroup rg = (radiogroup) p;                     rg.clearcheck();                 } else {                     // if radiobutton not belong radiogroup,                     // deselect                     rb.setchecked(false);                 }             }              // let's select clicked radiobutton             if (!v.getclass().equals(radiobutton.class)) {                 radiobutton rb = (radiobutton) v;                 rb.setchecked(true);             }          }     };      /**      *      ** returns id of radio button checked or -1 if none checked      *      * @return      */     public int getcheckedradiobuttonid() {         int checkedid = -1;         // loop each radio button         (radiobutton rb : radios) {             if (rb.ischecked())                 return rb.getid();         }         return checkedid;     }      public void setcheckedradiobutton(int pos) {         // let's deselect radios in group         (radiobutton rb : radios) {              viewparent p = rb.getparent();             if (p.getclass().equals(radiogroup.class)) {                 // if radiobutton belongs radiogroup,                 // deselect radios in                 radiogroup rg = (radiogroup) p;                 rg.clearcheck();             } else {                 // if radiobutton not belong radiogroup,                 // deselect                 rb.setchecked(false);             }         }         radios.get(pos).setchecked(true);     }       public void setcheckedradiobuttondefault() {         radios.get(0).setchecked(true);     }      @override     public void finalize() {         radios.clear();     }  } 

i need add radiobuttons programtically make radiobutton.xml:

<?xml version="1.0" encoding="utf-8"?> <radiobutton xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layoutdirection="rtl"     android:paddingstart="@dimen/padding_right_rests_columns"     android:paddingend="@dimen/padding_left_rest_column"     android:textalignment="center"     android:layout_centerhorizontal="true"     android:gravity="center"     android:layout_gravity="center"     android:layout_margin="5dp">  </radiobutton> 

and adding (this in fragment):

    gradiogroup gr = new gradiogroup();     radiobutton radiobutton = (radiobutton) getactivity().getlayoutinflater().inflate(r.layout.radiobutton, null);//initialize , set content radiobutton.settext("hey") // , settings want position ... //finally  gr.addradiobuttonstogroup(radiobutton); 

disadvantages? have handle selected radiogroup bundle or intents if activity/fragment/whatever destroyed.

hope you!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -