Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android dynamic radiobuttons id
  2. rb[i].setOnCheckedChangeListener(checkListener);
  3. //...
  4.        
  5. private OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
  6.  
  7.         @Override
  8.         public void onCheckedChanged(CompoundButton buttonView,
  9.                 boolean isChecked) {
  10.             for (int i = 0; i < count; i++) {
  11.                 if (buttonView.getId() == 5000 + i) {
  12.                     Log.e("XXX", "Position " + i);
  13.                 } else {                                      
  14.                     RadioButton rb = (RadioButton) findViewById((5000 + i));
  15.                     rb.setOnCheckedChangeListener(null);
  16.                     rb.setChecked(false);
  17.                     rb.setOnCheckedChangeListener(checkListener);
  18.                 }
  19.             }
  20.         }
  21.     };
  22.        
  23. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
  24.  {      
  25.     for (int i = 0; i < count; i++)
  26.   {
  27.     if (buttonView.isChecked())
  28.     {
  29.         // perform your task here
  30.     }
  31.     else
  32.     {
  33.         // Do something here.........
  34.     }
  35. }