Code example for CheckBox

Methods: performClick, setId

0
  @Test 
  public void onCheckRunnableWithMultipleIds() { 
    Activity activity = new Activity();
    FrameLayout root = new FrameLayout(activity);
 
    CheckBox checkbox1 = new CheckBox(activity);
    checkbox1.setId(android.R.id.button1);
    root.addView(checkbox1);
 
    CheckBox checkbox2 = new CheckBox(activity);
    checkbox2.setId(android.R.id.button2);
    root.addView(checkbox2);
 
    ViewFinder finder = new ViewFinder(root);
    final AtomicInteger run = new AtomicInteger(0);
    finder.onCheck(new Runnable() {
 
      public void run() { 
        run.incrementAndGet();
      } 
    }, android.R.id.button1, android.R.id.button2);
    checkbox1.performClick();
    assertEquals(1, run.get());
    checkbox2.performClick();
    assertEquals(2, run.get());
  }