your code updated, I hope it run well :D [Updated]
public class AutoCompleteTextViewActivity extends Activity implements TextWatcher {
/** Called when the activity is first created. */
private TextView selection;
private AutoCompleteTextView actv;
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
SimpleAdapter adapter;
private Suggest Suggestdetails;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selection);
actv=(AutoCompleteTextView)findViewById(R.id.actv);
String[] from = { "firstname","lastname","time","link"};
int[] to = { R.id.textView1,R.id.textView2,R.id.textView3,R.id.list_image};
adapter = new SimpleAdapter(AutoCompleteTextViewActivity.this,aList, R.layout.list_row,from,to);
actv.setAdapter(adapter);
actv.addTextChangedListener(this);
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (Suggestdetails!=null && Suggestdetails.getStatus().equals(AsyncTask.Status.RUNNING)){
Suggestdetails.cancel(true);
}
Suggestdetails=new Suggest();
Suggestdetails.execute();
}
public class Suggest extends AsyncTask<Void, Void, List<HashMap<String,String>>> {
@Override
protected List<HashMap<String,String>> doInBackground(Void... params) {
String ResponseBody = null;
try {
//geoaddress here
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/suggest.php");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("name", actv.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
if (isCancelled()) return null;
}
reader.close();
String result = sb.toString();
Log.d("Fb tr",result);
List<HashMap<String,String>> resultList = new ArrayList<HashMap<String,String>>();
if (isCancelled()) return null;
try{
JSONObject resultJson = new JSONObject(result);
JSONArray arr=resultJson.getJSONArray("Array");
for(int i=0;i<arr.length();i++)
{
JSONObject e1 = arr.getJSONObject(i);
JSONObject json= (JSONObject) e1.get("data");
String firstname = json.getString("firstname").trim();
String lastname = json.getString("lastname").trim();
String link = json.getString("link").trim();
String time = json.getString("time").trim();
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("firstname", firstname);
hm.put("lastname", lastname );
hm.put("link", link);
hm.put("time", time);
resultList.add(hm);
if (isCancelled()) return null;
}
}catch(Exception e){
e.printStackTrace();
}
return resultList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(List<HashMap<String,String>>... result) {
if (result != null) {
aList.clear();
aList.addAll(result[0]);
adapter.notifyDataSetChanged();
} else {
// error occured
}
}
}
}