Autocompletetextview不显示任何数据

时间:2014-11-05 03:30:34

标签: android google-maps

我从Places API获取了一个地方的名字。问题是我的自动完成TextView没有向我显示任何测试数据。我正在添加OK1,但是当我添加没有同步任务的内容时它没有显示任何内容它显示数据但是当我在文本字段中输入第二个字符时它会崩溃应用程序。

destiantion=(AutoCompleteTextView)findViewById(R.id.auto_complete_text);
destiantion.setThreshold(1);
resultList1=new ArrayList<String>();
destiantion.addTextChangedListener(new TextWatcher()
{
  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count)
  {

    String place=s.toString();
    final String url="http://maps.google.com/maps/api/geocode/json?"+"address="+place+"&sensor=true";
    try
    {
      //destiantion.setAdapter(new PlacesAutoCompleteAdapter(StartJourney.this, R.layout.auto_complete_items));
      //destiantion=(AutoCompleteTextView)findViewById(R.id.auto_complete_text);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    class innerClass extends AsyncTask<String, Object, Object>
    {

      @Override
      protected Object doInBackground(String... params)
      {
        // TODO Auto-generated method stub
        Network netwrok=new Network();
        try {
          String response=netwrok.sendData(url,"TEST");



        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        return null;
      }

      @Override
      protected void onPostExecute(Object result)
      {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        resultList1.add("OK1");
        destiantion.setAdapter(new PlacesAutoCompleteAdapter(StartJourney.this, R.layout.auto_complete_items));
      }
    }
    new innerClass().execute();
  }

适配器类是

private class PlacesAutoCompleteAdapter extends ArrayAdapter<String> implements Filterable {
  private ArrayList<String> resultList;

  public PlacesAutoCompleteAdapter(Context context, int textViewResourceId) {
      super(context, textViewResourceId);
      System.out.println("ENTER IN AUTO COMPLETE");
  }

  @Override
  public int getCount() {
      return resultList.size();

  }

  @Override
  public String getItem(int index) {
      return resultList.get(index);
  }

  @Override
  public Filter getFilter() {
    System.out.println("ENTER IN FILTER");
      Filter filter = new Filter() {
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              FilterResults filterResults = new FilterResults();
              if (constraint != null) {
                  // Retrieve the autocomplete results.
                  resultList =getResultList();
                  // Assign the data to the FilterResults
                  filterResults.values = resultList;
                  filterResults.count = resultList.size();
              }
              return filterResults;
          }

          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
            System.out.println(results.count);
              if (results != null && results.count > 0) {
                  notifyDataSetChanged();
              }
              else {
                  notifyDataSetInvalidated();
              }
          }
      };
      return filter;
  }
}

0 个答案:

没有答案