Making the Buttons DO something

Ok, so in the longest version of helloworld EVER, I needed to remember how to add actual functionality to this thing. I mean, the extra hard stuff I’ll figure out later (like downloading a file from my web site with the words in it – now that’s funny).

So my “final” version of the UI (user interface for your non-geeks) looks like this:

I now have 5 letters across, and 6 rows down. I display the words that you have to search for (I made it Christmas themed for the moment). Lots of random letters appeared, a way to show you what words you’ve found, and what word you’re spelling out. I also made more buttons. One lets you re-scramble all of the words, and one checks your current word to see if it matches any of the words we’ve asked you to find.

So one of the magic pieces to this is that all of the letter buttons call the same procedure called “tryMe”.

The really cool thing about android is that you can edit the buttons easily using XML instead of having to edit each property manually.

Here’s one of the various buttons and all of their settings. Now I kind of feel like I should be creating these automatically, but I’m not. So there’s lots of manual work behind the scene to make this whole thing work. You know what? Oh well.

So the various pieces to this image are settings in the button itself. The text doesn’t really matter since it’s a toggle button.

I set the width manually because I wanted it slightly smaller than the standard button.

The height, I do want them all to wrap nicely, so I left that alone.

The ID, for each one I called them R # C #, so as to easily track which one is which. (This button is the 5th row and the first column.)

I wanted to set the on/off text in the background, so I set them both to nothing.

“On Click” means, go do something called “tryMe” every time someone clicks this button. (Remember cause and effect?)

Layout_Row & Column are just “in this giant grid of things, where does this go?”

private void tryMe(View view){

    ToggleButton myButton = (ToggleButton) findViewById(view.getId());
    TextView tv = (TextView) findViewById(;
    if(anyChecked()) {
        if (myButton.isChecked()) {
            mySelectedItem += myButton.getTextOff().toString();

            mySelectedItem = mySelectedItem.substring(0,mySelectedItem.length()-1);
    else {
        mySelectedItem = "";
    tv.setText("You're Spelling: " + mySelectedItem);

The above is my code for each button click.  I’m going to assume that you know what a procedure is. If you don’t, I’ll add something to explain these later.

The first line references the button that was clicked. Basically “tell me what was clicked.”

Next I link the label (or TextView as Android calls them) to the text that I want to show the user what they’re spelling.

If this isn’t someone clicking on their very last button, and I’ve actually set this button to be checked, I grab the text from the button and put it into a variable to hold for later.

If this isn’t someone clicking on their very last button, but this button has just been unchecked, then I want to remove the last letter.

On the other hand, if someone is clicking on the very last button (everything else is unchecked), remove my text completely.

Finally, I set the label to say whatever the person has been doing.

Lots of words, but basically every time someone clicks a button, it adds a letter to the label.

A New Game

I’m thinking about creating a new game. I’m trying to decide between a simple word search game, or maybe some kind of simple RPG.

Now the funny thing is, I can actually draw. I’m okay at it, but with carpal tunnel, it’s not my favorite past time. The RPG of course wouldn’t be sparkly CGI or fancy graphics. I mean, I am one person, and I do have a full time (sometimes more than) job.

If I did the RPG, I’d also have to think up a story, which I also enjoy doing. I’m just worried about the entire time it would take to get something like that out the door.

The Wordsearch on the other hand, is one of those games I love playing. It’s simple to play, mind-numbing and something that would go well on my site.

So I think I could get out the word search faster than the RPG, but both would take some time to do. I’m leaning towards the word search first, while I play with the story for an RPG.

What do you think?

Oh, and here’s a cute cat for you to look at.