android - 自动完成 TextView 从 android 中的服务器填充

标签 android autocompletetextview

我需要从服务器获取数据并填充到 android 的 autocompleteTextView 中。 我在 onPerformFiltering() 中获取并在 onPublishResults() 中显示的地方使用了自定义过滤器。 但我不需要为每个字符更改从服务器获取数据。我需要为特定长度的字符执行此操作。 我该怎么做?

最佳答案

class ProcessUpdater extends AsyncTask <Void, Void, Void>{

            @Override
            protected Void doInBackground(Void... params) {
                // TODO Auto-generated method stub

                    DefaultHttpClient httpclient = new DefaultHttpClient();
                    HttpGet httpget = new HttpGet("url");
                    HttpResponse response = httpclient.execute(httpget);
                    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    String NL = System.getProperty("line.separator");
                    while ((line = in.readLine()) != null) {
                        sb.append(line + NL);
                    }
                    in.close();
                    String result = sb.toString();
                    Log.v("My Response :: ", result);
                    JSONObject jsonObject = new JSONObject(result);
                    JSONArray resultArray = jsonObject.getJSONArray("Process");
                    for (int i = 0; i < resultArray.length(); i++) {
                        JSONObject c = resultArray.getJSONObject(i);
                        String sbs = c.getString("ProcessCode");
                        ProcessList.add(sbs);
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                }
                return null;
            }
            @Override
            protected void onPostExecute(Void result) {
                SelectProcess.setAdapter(new ArrayAdapter<String>(youractivtyname.this, android.R.layout.simple_dropdown_item_1line, ProcessList));

            }
        }

关于android - 自动完成 TextView 从 android 中的服务器填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11160519/

相关文章:

android - Xamarin.Forms。 SwipeGesture 和 ScrollView 不能在 Android 上协同工作

java - 自动完成 textview google places api

Android AutoCompleteTextView 显示选中的

android - 在 fragment 中调用 getSystemServices 时未定义?

android - 需要 bool 类型的值 : Popup Menu

android - 带有着色器的 HUD (opengl-es 2.0)

android - AutocompleteTextview 和 CompletionHintView

android - 如何为 AutoCompleteTextView 创建我自己的下拉 View ?

android - @Mention 使用 Multiautocompletetextview

android - 重置后单击 RadioButton 无操作