Question

Suppose I have a String "CAA". What I am doing now is randomly adding some Character to it for e.g. lets say I am adding Character 'B' and 'D' and shuffle that whole Character ArrayList and placing them in some Buttons as below

enter image description here

Here my character ArrayList contains {'A','C','B','A','D'}

What I am trying to do is when I click on a button I want something like below enter image description here

I mean only keep the Buttons that contain letters of Original string and disable all other Buttons.

Was it helpful?

Solution

  1. Create a Custom Class that wraps a Character and a boolean flag to maintain that its original character.

     class MyCharacter {
       private Character c;
       private boolean isOriginal;
    
       public MyCharacter(Character c, boolean isOriginal) {
           this.c = c;
           this.isOriginal = isOriginal;
       }
    
       public Character getChar() {
           return c;
       }
    
       public boolean isOriginal() {
           return isOriginal;
       }
     } 
    
  2. Instead of adding Character into list. Add MyChracter object.

  3. For original chracters pass boolean true in constructor and for later random ones pass false in it.

  4. Do shuffling or whatever you want. At any moment iterate over the list. Get the MyChracter object and check whether its original or not.

This should be simple to do. Hope this helps

Cheers

OTHER TIPS

You could keep several different ArrayLists. One holds the characters that you display, one holds the original, and then when a button is clicked test to see if a button is in the original ArrayList before graying it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top