Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:08:52+00:00 2026-06-06T07:08:52+00:00

I am trying to use auto completion in my app. After searching for a

  • 0

I am trying to use auto completion in my app.

After searching for a while i found the following tutorial:

http://www.claytical.com/blog/android-dynamic-autocompletion-using-google-places-api

There is a unresolved variable called s. where the URL is beeing created:

URLEncoder.encode(s.toString(), "UTF-8") +

I can not understand where this variable comes from.

Here is pretty much the whole code from the tutorial adapted a little bit.

public class PlacesListSearchActivity extends Activity {

    private static final String TAG = "PlacesListActivity";

    public ArrayAdapter<String> adapter;
    public AutoCompleteTextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.places_search);
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.item_list);
        final AutoCompleteTextView textView = (AutoCompleteTextView)
        findViewById(R.id.autoCompleteTextView1);
        adapter.setNotifyOnChange(true);
        textView.setAdapter(adapter);
        textView.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (count%3 == 1) {
                adapter.clear();
                    GetPlaces task = new GetPlaces();
                    //now pass the argument in the textview to the task
                    task.execute(textView.getText().toString());
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
        // TODO Auto-generated method stub

        }

        public void afterTextChanged(Editable s) {

        }

        });
    }

    class GetPlaces extends AsyncTask<String, Void, ArrayList<String>> {

        @Override
        // three dots is java for an array of strings
        protected ArrayList<String> doInBackground(String... args)
        {
            Log.d("gottaGo", "doInBackground");

            ArrayList<String> predictionsArr = new ArrayList<String>();

            try
            {
                //https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&sensor=true&key=AddYourOwnKeyHere
                URL googlePlaces = new URL(
                        "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" +
                        URLEncoder.encode(s.toString(), "UTF-8") +
                        "&types=geocode&language=en&sensor=true&key=" +
                        getResources().getString(R.string.googleAPIKey));

                URLConnection tc = googlePlaces.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        tc.getInputStream()));

                String line;
                StringBuffer sb = new StringBuffer();
                //take Google's legible JSON and turn it into one big string.
                while ((line = in.readLine()) != null) {
                    sb.append(line);
                }
                //turn that string into a JSON object
                JSONObject predictions = new JSONObject(sb.toString()); 
                //now get the JSON array that's inside that object            
                JSONArray ja = new JSONArray(predictions.getString("predictions"));

                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = (JSONObject) ja.get(i);
                    //add each entry to our array
                    predictionsArr.add(jo.getString("description"));
                }
            } catch (IOException e)
            {
            Log.e("YourApp", "GetPlaces : doInBackground", e);
            } catch (JSONException e)
            {
            Log.e("YourApp", "GetPlaces : doInBackground", e);
            }

            return predictionsArr;
        }

        //then our post

        @Override
        protected void onPostExecute(ArrayList<String> result){

        Log.d("YourApp", "onPostExecute : " + result.size());
        //update the adapter
        adapter = new ArrayAdapter<String>(getBaseContext(), R.layout.item_list);
        adapter.setNotifyOnChange(true);
        //attach the adapter to textview
        textView.setAdapter(adapter);

        for (String string : result) {
            Log.d("YourApp", "onPostExecute : result = " + string);
            adapter.add(string);
            adapter.notifyDataSetChanged();
        }

        Log.d("YourApp", "onPostExecute : autoCompleteAdapter" + adapter.getCount());

        }

    }

}

Ok, I answered my own question. See answer below!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:08:53+00:00Added an answer on June 6, 2026 at 7:08 am

    ok, I got it.
    The URL above should be calculated this way:

                URL googlePlaces = new URL(
                        "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" +
                        URLEncoder.encode(args[0], "UTF-8") +
                        "&types=geocode&language=en&sensor=true&key=" +
                        getResources().getString(R.string.googleAPIKey));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
At the following code I am trying to use Boost Spirit Auto Parser for
I am trying use a Java Uploader in a ROR app (for its ease
I am trying to use Auto-implemented properties in VS2005. I have .NET 3.0 framework
I am trying to use AJAX to populate some select boxes that were auto-generated
Im trying to use expect to auto accept an EULA that is prompted in
I am trying to use the new Auto Layout in Lion because it seems
Im trying to use auto indexing with the neo4j REST server (Community - 1.4.M04).
I'm trying to use an auto-complete widget that gets its data from a remote
I'm trying to use auto-generated forms in symfony, but I have troubles finding good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.