【问题标题】:ANDROID AutoComplete using AsyncTaskANDROID 使用 AsyncTask 自动完成
【发布时间】:2016-07-28 05:24:51
【问题描述】:

我的布局中有一个 AutoCompleteTextView,我想做一个 API 调用,它将输入的第一个字符作为参数。我在 AsyncTask 中执行此 API 调用,我将第一个字符作为参数传递给它。

我应该在 AutoCompleteTextView 上使用什么侦听器,以便在输入第一个字符后立即调用 AsyncTask?

【问题讨论】:

  • this
  • 使用 addTextChangedListener 修复了这个问题。
  • @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.toString().trim().length() == 1) { mAirport = new AsyncTaskAirport(s.toString()); mAirport.execute((Void) null); }
  • 您不需要任何TextWatcherAsyncTask,请参阅我在上面发布的链接

标签: android android-asynctask autocomplete


【解决方案1】:

【讨论】:

    【解决方案2】:

    使用 addTextChangedListener 修复了这个问题。

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().trim().length() == 1) {
                    isFileReceived = false;
                    mAirport = new AsyncTaskAirport(s.toString());
                    mAirport.execute((Void) null);
                }
    

    【讨论】:

      猜你喜欢
      • 2016-07-08
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 2015-04-20
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      相关资源
      最近更新 更多