如何获取autocomplettextview的ID?(How to get id of autocomplettextview?)

编程入门 行业动态 更新时间:2024-10-25 04:19:13
如何获取autocomplettextview的ID?(How to get id of autocomplettextview?)

我有两个autocompletetextview,在我的第一个自动填充中,我收到来自服务器的响应,

{"status":"success","clientlist":[{"cid":"1","name":"margi"},{"cid":"2","name":"steven"}],"productboxtype":[{"pbxid":"1","pbxname":"1 Dozen","qtyperbox":"12"},{"pbxid":"2","pbxname":"2 Dozens","qtyperbox":"24"},{"pbxid":"3","pbxname":"3 Dozens","qtyperbox":"36"}]}

我能够在我的第一个自动完成中获取名称,它工作正常,

现在问题是假设用户选择项目“margi”并且其cid为1,所以我再次向服务器发送请求并尝试获取“margi”的产品名称,其响应是

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1"}]}

但是在选择史蒂文之后仍然显示第二次自动完成时的kangan pari

@Override protected String doInBackground(String...args) { //Check for success tag //int success; Looper.prepare(); try { JsonParseClientList jp=new JsonParseClientList(); List<NameValuePair> params = new ArrayList<NameValuePair>(); List<SuggestGetSetClientList> list =jp.getParseJsonWCF(acTextView.getText().toString()); for(int i = 0;i<list.size();i++) { if(list.get(i).getName().equals(acTextView.getText().toString())) params.add(new BasicNameValuePair("cid",list.get(i).getId())); // catid=list.get(i).getId(); } for(int b=0;b<list.size();b++) { catidtemp=list.get(b).id.toString(); System.out.println("cattttttiiiiddd????"+catidtemp); break; } //catidtemp=String.valueOf(selected_cid); System.out.println("cattttttiiiiddd????"+catidtemp); params.add(new BasicNameValuePair("action", "clientproduct")); System.out.println("su gayu server ma????"+params); Log.d("request!", "starting"); // getting product details by making HTTP request JSONObject json = jsonParser.makeHttpRequest ( FEEDBACK_URL, "POST", params); //check your log for json response Log.d("Login attempt", json.toString()); return json.getString(FEEDBACK_SUCCESS); }catch (JSONException e) { e.printStackTrace(); } return null; } // After completing background task Dismiss the progress dialog protected void onPostExecute(String file_url) { //dismiss the dialog once product deleted pDialog.dismiss(); //parentcat.getText().clear(); }}

I have two autocompletetextview,in my first autocomplet,I am getting response from server,

{"status":"success","clientlist":[{"cid":"1","name":"margi"},{"cid":"2","name":"steven"}],"productboxtype":[{"pbxid":"1","pbxname":"1 Dozen","qtyperbox":"12"},{"pbxid":"2","pbxname":"2 Dozens","qtyperbox":"24"},{"pbxid":"3","pbxname":"3 Dozens","qtyperbox":"36"}]}

i am able to get names in my first autocomplete and it works fine,

Now issue is suppose user select item "margi" and its cid is 1,so again i am sending request to server and trying to get productnames of 'margi',and its response is

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1"}]}

but after selection of steven still it shows kangan pari in second autocomplete

@Override protected String doInBackground(String...args) { //Check for success tag //int success; Looper.prepare(); try { JsonParseClientList jp=new JsonParseClientList(); List<NameValuePair> params = new ArrayList<NameValuePair>(); List<SuggestGetSetClientList> list =jp.getParseJsonWCF(acTextView.getText().toString()); for(int i = 0;i<list.size();i++) { if(list.get(i).getName().equals(acTextView.getText().toString())) params.add(new BasicNameValuePair("cid",list.get(i).getId())); // catid=list.get(i).getId(); } for(int b=0;b<list.size();b++) { catidtemp=list.get(b).id.toString(); System.out.println("cattttttiiiiddd????"+catidtemp); break; } //catidtemp=String.valueOf(selected_cid); System.out.println("cattttttiiiiddd????"+catidtemp); params.add(new BasicNameValuePair("action", "clientproduct")); System.out.println("su gayu server ma????"+params); Log.d("request!", "starting"); // getting product details by making HTTP request JSONObject json = jsonParser.makeHttpRequest ( FEEDBACK_URL, "POST", params); //check your log for json response Log.d("Login attempt", json.toString()); return json.getString(FEEDBACK_SUCCESS); }catch (JSONException e) { e.printStackTrace(); } return null; } // After completing background task Dismiss the progress dialog protected void onPostExecute(String file_url) { //dismiss the dialog once product deleted pDialog.dismiss(); //parentcat.getText().clear(); }}

最满意答案

JSONObject resultObject = new JsonObject(result); //where result is {"status":"success","clientlist":[{"cid":"1","name":"margi"},{"cid":"2","name":"steven"}],"productboxtype":[{"pbxid":"1","pbxname":"1 Dozen","qtyperbox":"12"},{"pbxid":"2","pbxname":"2 Dozens","qtyperbox":"24"},{"pbxid":"3","pbxname":"3 Dozens","qtyperbox":"36"}]} JSONArray clientListArray = resultObject.getJSONArray("clientlist"); for (int i=0; i<clientListArray.length(); i++){ JSONObject client = clientListArray.getJSONObject(i); int id = client.getInt("cid"); ... Client clientInfo = new Client(id, name); clientList.add(clientInfo) .... }

然后,您可以将clientList用于适配器或其他内容。

您可以创建一个包含您的信息的课程

public class Client{ int id; String name; //getter and setter for this + constructor; }

要使代码检查不复杂,请访问: https : //code.google.com/p/google-gson/并查找一些可以更好地解释使用情况的教程

此外,如果您更改适配器信息,请不要忘记致电:

adapter.notifyDataSetChanged(); JSONObject resultObject = new JsonObject(result); //where result is {"status":"success","clientlist":[{"cid":"1","name":"margi"},{"cid":"2","name":"steven"}],"productboxtype":[{"pbxid":"1","pbxname":"1 Dozen","qtyperbox":"12"},{"pbxid":"2","pbxname":"2 Dozens","qtyperbox":"24"},{"pbxid":"3","pbxname":"3 Dozens","qtyperbox":"36"}]} JSONArray clientListArray = resultObject.getJSONArray("clientlist"); for (int i=0; i<clientListArray.length(); i++){ JSONObject client = clientListArray.getJSONObject(i); int id = client.getInt("cid"); ... Client clientInfo = new Client(id, name); clientList.add(clientInfo) .... }

Then you can use the clientList into an adapter or something else.

You can make a class that holds your info

public class Client{ int id; String name; //getter and setter for this + constructor; }

To not complicate your code check: https://code.google.com/p/google-gson/ and look for some tutorials that explains better the usage

Also if you change adapter info don't forget to call:

adapter.notifyDataSetChanged();

更多推荐

本文发布于:2023-08-02 08:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:autocomplettextview   ID   id

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!