How to Get user input from a Text Entry Box in Android?

Posted by NewGuy on Stack Overflow See other posts from Stack Overflow or by NewGuy
Published on 2011-11-21T00:02:36Z Indexed on 2011/11/21 1:51 UTC
Read the original article Hit count: 256

in an android website, I found an article about how to create a text entry widget that provides auto-complete suggestions. (Following is the link to the site; and it shows all the codes).

http://developer.android.com/resources/tutorials/views/hello-autocomplete.html

Can anyone please tell me how I can capture the input entered by the user? For example, if the user chooses “Canada”, is there a way I can know the result in the “HelloAutoComplete.java” activity? Any help would be greatly appreciated.

public class HelloAutoComplete extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
    String[] countries = getResources().getStringArray(R.array.countries_array);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, countries);
    textView.setAdapter(adapter);       




    textView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (adapterView.getItemAtPosition(i).toString().equals("Canada")) {
                Toast.makeText(getApplicationContext(), "Result Canada", Toast.LENGTH_SHORT).show();
            }  //Does not get an out put when I select Canada.
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

}  }

enter image description here

© Stack Overflow or respective owner

Related posts about java

Related posts about android