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(R.id.current_word);
    if(anyChecked()) {
        if (myButton.isChecked()) {
            mySelectedItem += myButton.getTextOff().toString();

        }
        else{
            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.

Re-Learning Android Development, Layouts

It’s been about a year since I did anything with Android Studio. Let me tell you, if you don’t use it, you lose it.

When I first started yesterday, I had absolutely no clue what I was doing. I mean, I could place some layouts and buttons and such, but making them do something? Hah.

So I did what any programmer does. I googled. And went to Android Development’s website and did their demo of creating an app.

And I remembered, slowly, bit by bit what it means to develop Android Apps.

Honestly, it’s like almost all development in today’s day. You have your UI Layer, where everything is organized. In Android, they have these things called “Layout Views” which let you easily layout buttons, text, etc.

So that way, when you’re setting up something (like say a grid of buttons with letters on them), you can set them up in rows of 4 columns without having to mess with a lot of css. Not that I don’t mind CSS, but it’s nice, drag and drop kind of easy.

Next up, is making those buttons…DO something.

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.

Happy Friday!

I don’t know about you, but man am I happy it’s Friday!

We went to see Star Wars: Rogue One at 1:30AM, so I’m a bit tired today. (I also had a full work day on top of it!) The movie itself was awesome, but I’m about ready to fall over.

I also remembered tonight that my hosting service was expiring, so I needed to find a new home. I had previously had a wonderful free service for a couple of years, so it’d been awhile since I shopped around.

I ended up using eHost because of both the price, and it seemed that they had good services.  Thankfully I keep all of my website files local, so I was able to upload them fast. I also have my domain name kept on a separate service.

All in all it took about one or two hours to get everything up and running.

I also decided to add a blog to show people what I can do on WordPress. Have something you’re looking for your blog? Leave me an idea in the comments, and I’ll see what I can do on the site.