Reputation: 733
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
Upvotes: 0
Views: 70
Reputation: 4934
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);
Upvotes: 2