DroidForums.net is the original Verizon Android Forum! Registered Users do not see these ads. Please Register - It's Free!
Results 1 to 2 of 2

Thread: Need help with textbox and button

  1. Junior Droid
    BiggiePhat's Avatar
    Member #
    Join Date
    Nov 2009

    Need help with textbox and button

    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?
  3. Droid
    skourg3's Avatar
    Member #
    Join Date
    Dec 2009
    Motorola Droid
    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 by skourg3; 06-22-2010 at 03:50 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Similar Threads

  1. Do I always have to tap the top button?
    By Neko in forum Android General Discussions
    Replies: 9
    Last Post: 01-28-2010, 10:38 AM
  2. Is there a button that acts as an "Enter" button while texting?
    By itslikecody in forum Android General Discussions
    Replies: 16
    Last Post: 01-12-2010, 10:30 PM
  3. add button does nothing
    By mattp5302 in forum Android Tech Support
    Replies: 1
    Last Post: 01-10-2010, 04:03 PM
  4. on/off button
    By asmallchild in forum Android General Discussions
    Replies: 6
    Last Post: 12-29-2009, 06:08 PM
  5. Any way to remap the camera/volume button to be the power button?
    By Flowah in forum Android Hacks and Help
    Replies: 2
    Last Post: 12-13-2009, 08:12 AM

Search tags for this page

android development textbox
android get textbox value
android text box example

android textbox


android textbox example


android textbox tutorial

android textbox value
how to code button array android
textbox android
textbox android example
Click on a term to search our site for related topics.
Find us on Google+