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) {
}
});
} }