自动完成的TextView在Android的服务器填充 [英] Autocomplete TextView populate from server in android

查看:147
本文介绍了自动完成的TextView在Android的服务器填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从服务器上获取数据,并在机器人的autocompleteTextView填充。
我已经用了,我在onPerformFiltering(获取相同),并显示自定义过滤器在onPublishResults()。
但我不需要从服务器获取数据,每个字符Change.I需要做它的字符特定长度。
我怎样才能做到这一点?


解决方案

 类ProcessUpdater扩展的AsyncTask<太虚,太虚,太虚> {            @覆盖
            保护无效doInBackground(虚空...... PARAMS){
                // TODO自动生成方法存根                    DefaultHttpClient的HttpClient =新DefaultHttpClient();
                    HTTPGET HTTPGET =新HTTPGET(URL);
                    HTT presponse响应= httpclient.execute(HTTPGET);
                    在的BufferedReader =新的BufferedReader(新的InputStreamReader(response.getEntity()的getContent()));
                    StringBuffer的SB =新的StringBuffer();
                    串线=;
                    串NL = System.getProperty(line.separator);
                    而((行= in.readLine())!= NULL){
                        sb.append(行+ NL);
                    }
                    附寄();
                    字符串结果= sb.toString();
                    Log.v(我的回答::,结果);
                    的JSONObject的JSONObject =新的JSONObject(结果);
                    JSONArray resultArray = jsonObject.getJSONArray(过程);
                    的for(int i = 0; I< resultArray.length();我++){
                        JSONObject的C = resultArray.getJSONObject(I)
                        字符串SBS = c.getString(过程code);
                        ProcessList.add(SBS);
                    }
                }赶上(例外五){
                    // TODO:处理异常
                }
                返回null;
            }
            @覆盖
            保护无效onPostExecute(虚空结果){
                SelectProcess.setAdapter(新ArrayAdapter<串GT;(youractivtyname.this,android.R.layout.simple_dropdown_item_1line,ProcessList中));            }
        }

I need to fetch data from server and populate in autocompleteTextView in android. I have used a custom filter for the same where I fetch in onPerformFiltering() and display in onPublishResults(). But I need not fetch data from the server for every character Change.I need to do it for specific length of characters. How can I do this?

解决方案

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

            }
        }

这篇关于自动完成的TextView在Android的服务器填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆