DIsclaimer: To make this kind of app, it is extremely helpful if you have some understanding of the Android Development Environments for example Eclipse or Android Studio. It is also helpful if you have some understanding of basic level Java. However, in case you don't have a clue what I just said;;for your convenience, all essential programming terms/jargon are highlighted and once clicked, provide a link to other explanatory material and/or definitions. I aim to please :-)
The term wireframing has a few distinctive definitions floating out there in cyberspace, but one of the best I have seen goes as follows: "It is a visual guide that represents the skeletal framework of a website, app, program, anything that involves a UI (User Interface). In figure 1 (located above), I have done some very simple wireframing to clearly depict what we will be doing for this app.
At the start of the app, we will have an Input Form that asks the user to input some words on the given textfields (lines). After the user is done with the input, they press a button labelled "Get My Mad Lib" and this makes the program display another page....the Output Form. As you would expect, the Output Form has some text (maybe a paragraph or two), and within this text you will find the words that you just input into the Input Form.
To create this very simple example of wireframing I used Balsamiq (a very popular wireframing tool). However, there are many others that you can use. Check out this list to see what I mean. Whether you are part of a development team, a solo programmer, or a client looking to have a program/app developed for you; you can use wireframing as a great communication and organization tool.
Designing The UI
To better follow along with the rest of the tutorial, I suggest placing the following xml code in your project. The first piece of XML code, once placed in your project, will display an input form much like the one seen in Figure 2.). The second piece of XML code, once placed in your project, will display an input form much like the one seen in Figure 3.). The input form is obviously the more complicated of the two, and for good reason. There are about 7 to 8 variables that you need from the input form to make computations, while the output form just has a single textview where you display your text.
Also, as a note; in this project I have named the input file...main_class_activity_in.xml. And the output file is named main_class_activity_out.xml. These file names will also serve as id when calling (R.id.[file name]).
Furthermore, while sometimes you do not need to give the various components in the xml files (views) ids; in order to get the program to work properly you should give ids to the at least these 2 viewswhich I have already named.
Lastly, it is difficult to see from Figure 3.) but the text within the textview with id -- "outview14" located in main_class_activity_out.xml has the occasional string "wx" inserted where normally you would find proper english word. These "wx's" will be replaced with entries for your mad lib.
Mad Libs Input Form Code:
Mad Libs Output Form Code:
Code: That ties it all together
I just wanted to take time to provide a quick summary of the above code. After declaring all of our essential variables and initializing some layouts and other views in onCreate(), The following three methods do the actual work of the program.
First, when the user clicks the button on main_class_activity_in.xml, it calls the onClick method located in the code above. This method then in turn calls the methods gather() and postIt().
The gather() method first initializes the layout "anskey_clover" to a ViewGroup which I have called "layout." Once you have a ViewGroup object defined, you can search its child views (views/widgets contained within another view). In this case, the layout "anskey_clover" has a bunch of child views --- 7 AutoCompleteTextviews to be exact. The code will gather the values from these AutoCompleteTextviews and put them in a StringBuffer object called stringbuffer. All of this is done using for loops.
Then if we go back to the onClick method, we see that it calls the postIt() method. And in a nutshell what the postIt() medthod does is
- Sets the screen to the layout file main_class_activity_out.xml using the setContentView() method.
- Use the stringbuffer in conjunction with the split() method to create an array containing the inputs from the AutoCompleteTextviews. The array object is called "stringviews."
- Create a TextView object that is linked to the TextView in main_class_activity_out.xml. The one that has id -- "outview14". In the code, this TextView object is simply called "outview."
- Get the string from "outview" and replace all the "wx"'s in it, with the values from the object "stringviews."
And that should be it. You are now done with a simple mad libs app! :) If you have any questions about implementation, leave them in the comments section below.