我有两个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();
}}
答案 0 :(得分:0)
如果你想比较'boxqty'和'minimum_qty',在if条件下,你不应该为boxqty使用它.length(),因为它只会计算字符串的长度,用户将输入,而不是它的值。
答案 1 :(得分:0)
我想当你选择&#34;史蒂文&#34;你得到clientproduct数组null作为响应。这就是为什么调用catch块并且你的秒自动完成数组不清楚的原因。这就是您在第二次自动填充中获得之前值的原因。
希望你能理解:) 快乐编码:)
答案 2 :(得分:0)
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();