Question

I try to get the string I wrote in the autocomplete to use it later

AutoCompleteTextView from_txt;
List<String> country_List;
ArrayAdapter<String> adapter;

then

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   AutoCompleteTextView from_txt = (AutoCompleteTextView) findViewById(R.id.from_txt);
    from_txt.setThreshold(1);
 from_txt.addTextChangedListener( this);
    adapter = new ArrayAdapter<String>
 (this,android.R.layout.simple_dropdown_item_1line,country_List);
    from_txt.setAdapter(adapter);
    handler = new Handler();

then I try to get the text

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {


    Toast.makeText(getApplicationContext(), from_txt.getText(), Toast.LENGTH_LONG).show();  

}

but this doesn't work

Was it helpful?

Solution

The AutoCompleteTextView object is being defining twice. Just replace:

AutoCompleteTextView from_txt = (AutoCompleteTextView) findViewById(R.id.from_txt);

with:

from_txt = (AutoCompleteTextView) findViewById(R.id.from_txt);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top