gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:57:38 25 4
gpt4 key购买 nike

我需要从服务器获取数据并填充到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com