Need help with textbox and button

Discussion in 'Android Hacks and Help' started by BiggiePhat, Jun 21, 2010.

  1. BiggiePhat

    BiggiePhat New Member

    Joined:
    Nov 1, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    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")
    gotoThisWebpage("www.webpage.com");
    else if (text = "b")
    gotoThisWebpage("www.webpage2.com");

    and etc.

    how can this be done?
     
  2. skourg3

    skourg3 Member

    Joined:
    Dec 14, 2009
    Messages:
    70
    Likes Received:
    0
    Trophy Points:
    6
    Ratings:
    +0
    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(R.id.IdOfYourBox); //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: Jun 22, 2010
Search tags for this page
android getting data from textbox
,
android sdk change the value of text box
,
android textbox go button
,
change the textbox size android
,
get text box value in android develop
,

how to code button array android

,
how to get textbox values in next page in android
,
how to send the value from button to textbox in android
,
string compare textbox in eclipse android
,

textbox android