代码不起作用。请帮忙。除数量外,该项目被添加到数据库中。它始终为零。这是为什么?
String value;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.creamy);
EditText et = (EditText) findViewById(R.id.CreamyEdit);
value = et.getText().toString();
Button b = (Button) findViewById(R.id.buttonCreamy);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(Creamy.this, "Item Submitted", Toast.LENGTH_LONG).show();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://10.0.2.2:8080/http/test.php");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("item", "Creamy Delight")); //reflected in db
pairs.add(new BasicNameValuePair("quantity", value)); //not reflected in db
try {
post.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
HttpResponse response = client.execute(post);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
});
请帮忙!