2

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

4

1 回答 1

0
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));

            }
        }
于 2013-09-21T11:26:31.623 回答