title: How to use post method in android using json
body: <p>I have created an android apps using json for getting from ror website and displaying in listview,Right now i want to add the data from our apps,it has to display in listview in our apps also and then it has to show in website also.How to use post method and display in our apps.</p>
  
  <p>to get method i used like that </p>
  
  <pre><code>public class MainActivity extends ListActivity implements FetchDataListener
  {
      private ProgressDialog dialog;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          //setContentView(R.layout.activity_list_item);   
          initView();
      }
  
      private void initView()
      {
          // show progress dialog
          dialog = ProgressDialog.show(this, "", "Loading...");
          String url = "http://floating-wildwood-1154.herokuapp.com/posts.json";
          FetchDataTask task = new FetchDataTask(this);
          task.execute(url);
      }
  
      @Override
      public void onFetchComplete(List&lt;Application&gt; data)
      {
          // dismiss the progress dialog
          if ( dialog != null )
              dialog.dismiss();
          // create new adapter
          ApplicationAdapter adapter = new ApplicationAdapter(this, data);
          // set the adapter to list
          setListAdapter(adapter);
      }
  
      @Override
      public void onFetchFailure(String msg)
      {
          // dismiss the progress dialog
          if ( dialog != null )
              dialog.dismiss();
          // show failure message
          Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>fetchdatatask.java</p>
  
  <pre><code>public class FetchDataTask extends AsyncTask&lt;String, Void, String&gt;
  {
      private final FetchDataListener listener;
      private String msg;
  
      public FetchDataTask(FetchDataListener listener)
      {
          this.listener = listener;
      }
  
      @Override
      protected String doInBackground(String... params)
      {
          if ( params == null )
              return null;
          // get url from params
          String url = params[0];
          try
          {
              // create http connection
              HttpClient client = new DefaultHttpClient();
              HttpGet httpget = new HttpGet(url);
              // connect
              HttpResponse response = client.execute(httpget);
              // get response
              HttpEntity entity = response.getEntity();
              if ( entity == null )
              {
                  msg = "No response from server";
                  return null;
              }
              // get response content and convert it to json string
              InputStream is = entity.getContent();
              return streamToString(is);
          }
          catch ( IOException e )
          {
              msg = "No Network Connection";
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String sJson)
      {
          if ( sJson == null )
          {
              if ( listener != null )
                  listener.onFetchFailure(msg);
              return;
          }
          try
          {
              // convert json string to json object
              JSONObject jsonObject = new JSONObject(sJson);
              JSONArray aJson = jsonObject.getJSONArray("post");
              // create apps list
              List&lt;Application&gt; apps = new ArrayList&lt;Application&gt;();
              for ( int i = 0; i &lt; aJson.length(); i++ )
              {
                  JSONObject json = aJson.getJSONObject(i);
                  Application app = new Application();
                  app.setContent(json.getString("content"));
                  // add the app to apps list
                  apps.add(app);
              }
              //notify the activity that fetch data has been complete
              if ( listener != null )
                  listener.onFetchComplete(apps);
          }
          catch ( JSONException e )
          {
              e.printStackTrace();
              msg = "Invalid response";
              if ( listener != null )
                  listener.onFetchFailure(msg);
              return;
          }
      }
  
      /**
       * This function will convert response stream into json string
       * 
       * @param is
       *            respons string
       * @return json string
       * @throws IOException
       */
      public String streamToString(final InputStream is) throws IOException
      {
          BufferedReader reader = new BufferedReader(new InputStreamReader(is));
          StringBuilder sb = new StringBuilder();
          String line = null;
          try
          {
              while ( (line = reader.readLine()) != null )
              {
                  sb.append(line + "\n");
              }
          }
          catch ( IOException e )
          {
              throw e;
          }
          finally
          {
              try
              {
                  is.close();
              }
              catch ( IOException e )
              {
                  throw e;
              }
          }
          return sb.toString();
      }
  }
  </code></pre>
  
  <p>Like this i am using get method and displaying also,for same purpose i want to add the post method to displaying in android listview and shown in website also.</p>
  
  <p><strong>if i will create one button if i click the menu button like add,in that one it will shows one page,in that page i have to add the data and click save,it has to display in listview and post in website also</strong></p>
  
  <p>How i can do that one.</p>