1

I am new to android i have implemented auto complete for map places. it is working fine when giving input without spaces, but when i am giving input with spaces results are not showing in android

This is following code I am using for auto complete.

fromlocation.addTextChangedListener(new AutoCompleteTextWatcher(fromlocation,"from",fromPlacesDetailsList,fromPlacesAdapter,getApplicationContext(),googleRestGateway));

For text watcher:

@Override
public void afterTextChanged(Editable s) 
{
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) 
{
}
@Override
public void onTextChanged(CharSequence placeInput, int start, int before, int count) 
{
    String place = placeInput.toString();
    if(place!=null && (place.length()>0 & place.length()<10))
    {
         {
             new AutoCompleteTask(placeDetails,adapter,appContext,googleRestGateway,textView).execute(place);
         }
    }


}

I am getting the placesDetailsList in both cases i.e; with spaces given and also without spaces this is code on how i am parsing the response.

protected void onPostExecute(List<HashMap<String, String>> placesDetailsList) 
{
    //Log.d(LogActivityTagNames.AUTO_COMPLETE_TASK, " Entered into onPostExecute() with " + placesDetailsList.toString());
    String[] from = new String[] { "description"};
    int[] to = new int[] { android.R.id.text1 };

    placesAdapter = new SimpleAdapter(ctx, placesDetailsList, android.R.layout.simple_dropdown_item_1line, from, to)
    {
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            View view = super.getView(position, convertView, parent);
             TextView text1 = (TextView) view.findViewById(android.R.id.text1);
            text1.setTextColor(Color.BLACK);

              return view;


        }
    };
    autoTextView.setAdapter(placesAdapter);     
}

This is the URL https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=true&input=kr+puram&types=geocode&key=AIzaSyD3nw5uC7ptOT6Kq57GJ6SvFyW3mHcWfaY. The above code is working fine without spaces as input, but when I am giving spaces results are coming but they are not displaying in emulator.

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
Manikanta
  • 3,421
  • 4
  • 30
  • 51
  • see my answer here: http://stackoverflow.com/questions/19858843/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara – pskink Jul 14 '14 at 05:05

2 Answers2

1

Try to replace space with %20,replace below code

new AutoCompleteTask(placeDetails,adapter,appContext,googleRestGateway,textView).execute(place.replace(" ","%20"));
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • It is not still working !!!. The problem is i am getting the response into PlacesAdapter but when executing autoTextView.setAdapter(placesAdapter); result is not coming . – Manikanta Jul 14 '14 at 04:17
0

It's working properly. It downloads the data but it's not setting them into the adapter. Just add:

autoTextView.setAdapter(adapter);
synchronized (placesAdapter){
  placesAdapter.notifyDataSetChanged();
} 
Aurasphere
  • 3,841
  • 12
  • 44
  • 71