You do not need to pass a value to the execute method. Set the name, price and description variables as global. To get the value from EditTest, click the Code button, as shown below:
Every time you need to click on a button to get JSON data.
btnSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { name = txtName.getText().toString(); price = txtPrice.getText().toString(); description = txtDesc.getText().toString(); new CreateNewProduct().execute(); } });
Now the name, price and description have the meaning that you entered.
Now your CreateNewProduct class looks like this:
class CreateNewProduct extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(NewProductActivity.this); pDialog.setMessage("Creating Product.."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } protected String doInBackground(String... args) { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("name", name)); params.add(new BasicNameValuePair("price", price)); params.add(new BasicNameValuePair("description", description)); JSONObject json = jsonParser.makeHttpRequest(url_create_product, "POST", params); Log.d("Create Response", json.toString()); try { int success = json.getInt(TAG_SUCCESS); if (success == 1) { Intent i = new Intent(getApplicationContext(), AllProductsActivity.class); startActivity(i); finish(); } else { } } catch (JSONException e) { e.printStackTrace(); } return null; } protected void onPostExecute(String file_url) { pDialog.dismiss(); }
}
Millu source share