Need help with textbox and button


New Member
Nov 1, 2009
Reaction score
I have an autocomplete text box that runs off of a string array i have coded in XML. the string array is pretty much just used for autocomplete as a nice added feature.

i want to compare the string in the textbox to a hard coded string (or some way to utilize the string array) to see what action to take when the go button is pressed.

For example pseudocode would be

when button is pressed{
if(text = "a")
else if (text = "b")

and etc.

how can this be done?


Dec 14, 2009
Reaction score
Of course, my desktop (with the sdk and eclipse installed/set up/having code on it) is currently non-functional, so I can't check specifics.. anyway, I don't know if this would be the optimal way of doing it, but.. note that my names/syntax are probably a little off, particularly when stuff does/n't require casting (I'm not familiar enough with the Android sdk to remember when stuff needs a cast or not). Also, I'm assuming you know how to set up the button.Click event listener; this code would go inside the onClick function.

AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(; //I think findViewById is the name of the function I'm thinking of..
string enteredText = actv.getText(); //Might need a string cast? Don't think so though
if(enteredText == "string1") {

/*Note that string1 could also be a value from an array, like option[0].. I'm not sure how to work with string resource arrays off the top of my head, though I assume you could manipulate R.string.something to get that value. You might have to cast it as a string (or use a function to retrieve it) to get it to work, as a lot of resources return an int value iirc, I don't know for sure. Anywho.. */

//TODO: Write some code for if string1
} elseif (enteredText == "string2") {
//TODO: Write some code for if string2
} else {
//TODO: Write fallback code, if you want it

Again, my experience with Android development is a little limited, so some corrections could be needed.. Also, if you have a bunch of options, you might want to go with a switch statement instead of a series of if/elseifs..
Last edited: