1

I follow this tutorial that I try to switch wikipedia json for google places json , but on output i dont receive results.

I guess my error it's when i try to do that

input = "input=" + constraint;

Can someone help me ?

 public class oi extends Activity {
            TextView teste;
            AutoCompleteTextView atvPlaces;


            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.oi);

                atvPlaces = (AutoCompleteTextView) findViewById(R.id.atv_places);
                teste = (TextView) findViewById(R.id.testes);
                atvPlaces.setThreshold(1);


                AutoCompleteTextView actv = new AutoCompleteTextView(this);
                actv.setThreshold(1);
                String[] from = {"name", "description"};
                int[] to = {android.R.id.text1, android.R.id.text2};
                SimpleCursorAdapter a = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, null, from, to, 0);
                a.setStringConversionColumn(1);
                FilterQueryProvider provider = new FilterQueryProvider() {
                    @Override
                    public Cursor runQuery(CharSequence constraint) {
                        // run in the zbackground thread
                        if (constraint == null) {
                            return null;
                        }


                        String[] columnNames = {BaseColumns._ID, "name", "description"};
                        MatrixCursor c = new MatrixCursor(columnNames);
                        try {
                            String data = "";

                            String key = "key=AIzaSyAQ_ZcIMsbGELnmPkk-43UwKVXlJbu1wwA";

                            String input="";

                            input = "input=" + constraint;




                            // place type to be searched
                            String types = "types=geocode";

                            // Sensor enabled
                            String sensor = "sensor=false";
                            input=input.replace(" ","+");
                            // Building the parameters to the web service
                            String parameters = input+"&"+types+"&"+sensor+"&"+key;

                            // Output format
                            String output = "json";

                            // Building the url to the web service
                            String urlString = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;


                            URL url = new URL(urlString);
                            InputStream stream = url.openStream();
                            BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
                            String jsonStr = reader.readLine();
                            // output ["query", ["n0", "n1", ..], ["d0", "d1", ..]]
                            JSONArray json = new JSONArray(jsonStr);
                            JSONArray names = json.getJSONArray(1);
                            JSONArray descriptions = json.getJSONArray(2);
                            for (int i = 0; i < names.length(); i++) {
                                c.newRow().add(i).add(names.getString(i)).add(descriptions.getString(i));
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return c;
                    }
                };
                a.setFilterQueryProvider(provider);
                actv.setAdapter(a);
                setContentView(actv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
Community
  • 1
  • 1
Tiago Coelho
  • 159
  • 6

0 Answers0