Reputation: 710
I have a class that fetches all the suggestions based on the text entered from the server. In the postExecute(), I am adding all the suggestions to my ArrayList and I want to set that arraylist as adapter. But it is not working.
The onCreate() code:
t1 = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
t1.setThreshold(1);
t1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
//DoPost() is the class fetching data from server
new DoPOST().execute("");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,Names);
t1.setAdapter(adp);
When I change the text, I can see the server response returning the data. And in postExecute():
for(int i=0 ;i<js.length();i++){
try {
JSONObject tokenobj=js.getJSONObject(i);
Names.add(tokenobj.get("suggestion").toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
So the suggestions are coming in the arraylist but it is not showing as the dropdown instantly.. Please help, Thanx in advance.
Upvotes: 0
Views: 530
Reputation: 7082
When the data (the ArrayList in this case) changes, you need to call .notifyDataSetChanged()
on the adapter instance in order for the view to redraw.
Upvotes: 1